How to find position of bookmark from word file using aspose c#

62 views Asked by At

I am working with aspose in c# and i want to know the x and y for the bookmark so that i can put something mannually.

i have tried this code

LayoutCollector layoutCollector = new LayoutCollector(document);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(document);

//signature bookmark start
BookmarkStart signatureBookmarkStart = document.Range.Bookmarks["signImage1"].BookmarkStart;

var renderObject = layoutCollector.GetEntity(signatureBookmarkStart);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;

but it gives wrong position.

1

There are 1 answers

0
Alexey Noskov On

First of all, please note that MS Word documents are flow by their nature, so there is no layout information in the document itself. The consumer applications, like MS Word or OpenOffice, reflows the document content into pages on the fly. Aspose.Words has it's own document layout engine.

To determine bookmark's or other node's coordinates it is required to build document layout. To built an accurate document layout the fonts used in your document should be available in the environment where the document is processed. If Aspose.Words cannot find the font used in the document, the font is substituted. This might lead into fonts mismatch and document layout differences due to the different fonts metrics and as a result incorrect node's coordinates returned by LayoutEnumerator. You can implement IWarningCallback to get notifications when font substitution is performed. By default Aspose.Words uses the font installed in the environment, but is is possible to explicitly specify location where Aspose.Words will look for fonts.

Also, in evaluation mode Aspose.Words injects an evaluation message at the top of the document, that might shift the document content and as a result coordinates detected by LayoutEnumerator will be shifted too.

If nothing from the above helps, post the question in Aspose.Words support forum and attach the problematic document there.