Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Apr 09, 2025 5:26 am

When merging multiple documents, requirement is to have a separate numbering for the first document.
The remaining documents being merged should follow a separate numbering starting from number 1.
How do i achieve this.

if(fileCount > 0 {
document.insertTextFromFile(fn.getAbsolutePath(), FileFormat.Docx_2013);
restartNumbering = false;
document.getLastSection().getPageSetup().setRestartPageNumbering(true);
document.getLastSection().getPageSetup().setPageStartingNumber(1);
}

I have tried the above, but the page number for the last document merged shows Page 9 of 10.
It should have been Page 9 of 9

suma_ar8
 
Posts: 8
Joined: Fri Jun 21, 2024 4:28 am

Wed Apr 09, 2025 6:51 am

Hello,

Thanks for your inquiry.
In Microsoft Word, the {PAGE} field displays the current page number, while the {NUMPAGES} field shows the total number of pages in the entire document. When there are multiple sections, the {NUMPAGES} field counts the total pages of the entire document, not just the pages of the current section. Therefore, when merging documents, you might see something like "Page 9 of 10," where "10" represents the total pages in the entire document, not the number of pages in the current section.
To avoid this issue, it is recommended to replace the {NUMPAGES} field with the {SECTIONPAGES} field. The {SECTIONPAGES} field counts only the total pages of the current section, ensuring that even after merging documents, the page range for each section is displayed correctly.
To verify or modify these fields, you can follow these steps:
1.Enable Field Codes:
In Word, press Alt + F9 to toggle the display of field codes. This allows you to see fields like {PAGE} of {NUMPAGES} or {PAGE} of {SECTIONPAGES}.
2.Modify the Fields:
Replace the {NUMPAGES} field in your document with {SECTIONPAGES}. This ensures that the total number of pages for each section is displayed correctly.
3.Update the Fields:
After making the changes, select all fields and press F9 to update them and ensure the new field values are displayed correctly.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 656
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.Doc