Hi there,
I am able to get the coordinate of nodes in a word document using the LayoutEnumerator and LayoutCollector. I am trying to draw a rectangle on a particular node after transforming the document to an Image:
This is the code I used to transform the document into an Image:
List pageImages = new List();
// the format being either PNG, JPG or GIF
SaveFormat saveFormat = GetFormat(imageOptions.ImageFormat);
ImageSaveOptions saveOptions = new
ImageSaveOptions(saveFormat);
for(int i= 0; i < _document.PageCount; i++)
{
MemoryStream stream = new MemoryStream();
saveOptions.PageIndex = i;
_document.Save(stream, saveOptions);
stream.Seek(0, SeekOrigin.Begin);
pageImages.Add(stream);
}
return pageImages;
When I render the stream to an Image and using the Graphics object draw a rectangle on the coordinates I obtained from the LayoutEnumerator, the position doesn’t match at all.
Things that I have tried:
1.) transforming the node( eg a span with text “we”) coordinates to pixels using this formula 1pt = 1.333333px.
2.) Obtaining through calculations the DPI settings Aspose uses to create the Image and adding that to the Y coord of a node.
3.) getting the page’s pixels from the points, subtracting the page’s heightInPoints from the page’s heightInPixels and dividing by 2 and adding to the Node’s Y coord.
I tried all the above and still, none of them maps the node’s coordinate to its position on the Image.
My question is this: I want to know if it’s possible to hook into the process of creating the Image and obtain the true coordinates of the node.
This is the doucment I am using for the process: source.zip (10.2 KB)