I want to get locations of each paragraph and table that passing through whole document and get their locations in pixels relative to top left of document page i.e. top left, top right, bottom left and bottom right.
I also need the rendering set to custom pixel size for e.g. 750 pixels of document before parsing through document.
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.
The LayoutCollector.GetEntity method returns 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.
Please check the following code example. Hope this helps you.
Document doc = new Document(MyDir + "input.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true))
{
if (paragraph.GetAncestor(NodeType.Table) == null)
{
enumerator.Current = collector.GetEntity(paragraph);
Console.WriteLine(enumerator.Rectangle);
}
}
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
enumerator.Current = collector.GetEntity(table.FirstRow.FirstCell.FirstParagraph);
Console.WriteLine(enumerator.Rectangle);
}
Thanks Tahir for the response, but it doesn’t serves my requirement, as I have to get bounds of whole paragraph i.e.:
This is a sample paragraph section:
2.4. Supplier is appointed to provide particular services to Customer10 related to facilities management (hard & soft) indicatively maintenance services, helpdesk service, environmental & energy management, security services, cleaning services, waste removal & pest control, mail, messenger & portering services, business centre management, reception & customer services, meeting & conference room management, audio visual services, catering –hospitality services and 3rd parties contracts management for Customer10 Premises & Assets, as described in Schedule 5.
Thanks for your inquiry. All text of the document is stored in runs of text. If you need to navigate to a Run of text then you can insert bookmark right before it and then navigate to the bookmark instead.
In your case, we suggest you please insert the bookmark at the end of paragraph and get the position of “.”. You can use the same approach shared in my previous post to get the position of “.”. You need to pass BookmarkStart node in LayoutCollector.GetEntity method. Hope this helps you.
Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.