Getting Pagenumber by Paragraph

Hello Aspose Team!
I´m using Aspose.Words for .Net to get the pagenumber of a specific Paragraph.
I´m already able to get the right pagenumber, but the docb.InsertField(“PAGE”) is very slow.
I have to tell you that the document is very big(411 pages) and complex too.
Is there any way to make the code faster? Here is the snipped I´m using:

DocumentBuilder docb = new DocumentBuilder(doc);
docb.MoveTo((Node) targetPara);
Aspose.Words.Fields.Field pageField = docb.InsertField("PAGE");
// docb.Document.UpdatePageLayout();
// pageField.Update();
int startPageCount = int.Parse(pageField.Result);
pageField.Remove();

The commented lines are slow too and it works without them, thats why I´m not using them anymore.
Please help me on

Hi Sallmutter,

Thanks for your inquiry.

I am afraid, currently there is no public API available to retrieve what page a Paragraph node is on. Microsoft Word document is a flow document and it does not contain any information about its layout into lines and pages; but, our internal ‘Rendering Engine’ layouts documents into lines and pages.

We have just finished integrating a feature into Aspose.Words’ API to open up access to the ‘Rendering Engine’ so that each element of the rendered document can be read as it appears as pages, columns, lines, spans etc. This functionality is exactly what you are looking for and will be available in the next version of Aspose.Words (13.1.0) which is due out in about next 24 hours. Your request has been linked to the appropriate issue (WORDSNET-2978) in our issue tracking system and you will be notified as soon as it the new release is published.

Best regards,

Thank you for your answer!
I´m looking forward to the new feature and hopefully there will be some sample code how to use it.
I´ll give my best to solve my problem with the new version and contact you if I need any assistance.
Best regards

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(3)

Hi Sallmutter,

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

For example, the LayoutCollector class collects mapping of document nodes to layout objects and computes page numbers of nodes.

When you create a LayoutCollector and specify a Document document object to attach to, the collector will record mapping of document nodes to layout objects when the document is formatted into pages.

You will be able to find out on which page a particular document node (e.g. run, paragraph or table cell) is located by using the GetStartPageIndex, GetEndPageIndex and GetNumPagesSpanned methods. These methods automatically build page layout model of the document and update fields if required.

Moreover, when you no longer need to collect layout information, it is best to set the Document property to null to avoid unnecessary collection of more layout mappings.

In addition, please try using the following sample code snippet:

Document doc = new Document(@"C:\temp\in.docx");
LayoutCollector lc = new LayoutCollector(doc);
Paragraph target = null;
foreach(Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    // Get the paragraph you want to find the Page Number of
    target = para;
}
if (target != null)
    Console.WriteLine(lc.GetStartPageIndex(target));

I hope, this helps.

Best regards,

Hi again!
I tried your sample code and it worked like a charm. The new feature made the performance of my program much better.
Thank you for your help!
best regards

Hi Sallmutter,

Thanks for your feedback. Please let us know any time you have any further queries. We’re always glad to help you.

Best regards,

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan