Is page break detection supported?

Hello,
I am using Aspose.Words to generate a pdf document using a .docx template and a JSON data source leveraging the ReportingEngine build report functionality.

I was wondering if there are any model/properties that represent page breaks and page numbers that can be used in the template to insert text similar to the one below
<<if [page_break == true]>> "Continued from <<page_number-1>>"<</if>>

I came across this post from 2009 https://forum.aspose.com/t/how-to-aspose-words-detect-page-break/99192 and wondered if there have been any updates since then.

Thank you in advance

@HanaLGC MS Word documents are flow by their nature, so there is no “page” concept. Consumer applications reflows document content into pages on the fly. So there is no way to get page index upon building the report.

You can try using standard MS Word IF and PAGE fields to achieve something similar to what you need:

For example see the following code and documents:

List<string> items = new List<string>();
for (int i = 0; i < 100; i++)
    items.Add($"item_{i}");

Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, items, "items");
doc.UpdateFields();
doc.Save(@"C:\Temp\out.docx");

in.docx (12.6 KB)
out.docx (12.0 KB)

Also, you can use LayoutCollector to determine page index of some particular node. So you can use this class to postprocess the report.

@alexey.noskov thank you, that is very helpful!

1 Like