We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Get cordinates of a word

Can your api get the cordiantes of a word and what page the word appear? I am trying to use this on rtf documents and trying to replace word interop

Hi there,

Thanks for your inquiry. The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages.

We suggest you please use LayoutCollector.GetEntity method to get an opaque position of the LayoutEnumerator which corresponds to the specified node. You can use returned value as an argument to Current given the document being enumerated and the document of the node are the same.

All text of the document is stored in runs of text. A run node may have single and multiple characters. If you need to navigate to a Run of text then you can insert bookmark right before it and then get the position of it. Please check the following code example.

Please also try EnumerateLayoutElements code example. Please get the code of "EnumerateLayoutElements" in Aspose.Words for .NET examples repository at GitHub. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

LayoutCollector collector = new LayoutCollector(doc);

LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

Bookmark bookmark = doc.Range.Bookmarks[0];

var renderObject = collector.GetEntity(bookmark.BookmarkStart);

layoutEnumerator.Current = renderObject;

Console.WriteLine(layoutEnumerator.Rectangle);