Free Support Forum - aspose.com

How to get starting and ending pages of each section

Hi,


We have been evaulating Aspose Words for Java in our company. We want to get the starting and ending page numbers of each section with respect to the whole document. Unfortunetely, we could not find any solution. We need to know whether it is possible.

Thanks

Hi,


Thanks for your inquiry. Sure, you can use the following code snippet to be able to get the starting/ending page number of a Section:
Document doc = new Document(“C:\Temp\in.docx”);
DocumentBuilder builder = new DocumentBuilder(doc);

builder.moveToSection(1);

Field startPageNumber = builder.insertField(“PAGE”);
Field pagesPerSection = builder.insertField(“SECTIONPAGES”);

doc.updatePageLayout();
doc.updateFields();

Integer endPageNumber = Integer.parseInt(startPageNumber.getResult()) + Integer.parseInt(pagesPerSection.getResult());

System.out.println(startPageNumber.getResult());
System.out.println(endPageNumber);

I hope, this helps.

Best regards,