Hi Simon,
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. The code of FindAndInsertBookmark class is attached with this post.
Moreover, you can use ListLevel.NumberPosition property to get or set the position (in points) of the number or bullet for the list level and ListLevel.TextPosition property get or set the position (in points) for the second line of wrapping text for the list level.
Hope this helps you.
Document doc = new Document(MyDir + "Example.docx");
// Iterate through all paragraphs in the document
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
Console.WriteLine(para.ParagraphFormat.LeftIndent);
if (para.IsListItem)
{
Console.WriteLine(para.ListFormat.List.ListLevels[0].NumberPosition);
Console.WriteLine(para.ListFormat.List.ListLevels[0].TextPosition);
}
}
Paragraph paragraph1 = (Paragraph)doc.GetChild(NodeType.Paragraph, 1, true);
paragraph1.Range.Replace("An example", "", new FindReplaceOptions { ReplacingCallback = new FindAndInsertBookmark("bookmark2") });
Bookmark bm = paragraph1.Range.Bookmarks["bookmark2"];
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
var renderObject = collector.GetEntity(bm.BookmarkStart);
layoutEnumerator.Current = renderObject;
RectangleF location2 = layoutEnumerator.Rectangle;
Console.WriteLine("Calculated position of 'An example'" + (location2.X - doc.FirstSection.PageSetup.LeftMargin));
bm.Remove();
doc.Save(MyDir + "output.docx");