Page numbering not being updated on combined documents

I have some code which combines a few templates together into a master document. The templates occasionally have different headers / footers, and occasionally different page setups.

The problem I am having is with the page numbering - the total number of pages is not being updated correctly in the resulting document.

I have attached 2 input files which are combined, and the resulting output document.

This code combines the input files:



Document doc1 = new Document(@“C:\test_in_1.doc”);
Document doc2 = new Document(@“C:\test_in_2.doc”);

this.AppendDoc(doc1, doc2);

doc1.Save(@“C:\test_out.doc”);


private void AppendDoc(Document dstDoc, Document srcDoc)
{
for (int sNum = 0; sNum < srcDoc.Sections.Count; sNum++) {
Section section = (Section)dstDoc.ImportNode(srcDoc.Sections[sNum], true);

dstDoc.Sections.Add(section);
}
}





The first page reports “Page 1 of 2”, when there are 4 pages. The other pages are okay.
If I update the Pages field within MS Word it is updated to the correct value.

For this simple case this is not such a big task, but the project I am working on combines lots of templates for the final output, and the page numbers need to be updated manually in each new sections.

Is there a way I can update the page numbers before saving?

Note: If I export the document to pdf using Aspose.PDF the page numbers are correct, so is this an MS Word problem?



Normally, MS Word automatically updates page count fields on openning. In your case it fails to do it correctly. It is MS Word problem - there is nothing we can do about it.

Best regards,