Free Support Forum -

Page Numbers on Footer when merging multiple documents

Using Aspose.Words, I am appending multiple documents into one. Each document uses the "X of Y" Page Number in the footer. I would like this numbering to apply to the entire final document. My first document is two pages long, the second is 3 pages long. The numbering shows "1 of 5", "2 of 5", "1 of 5", "2 of 5", "3 of 5". I would like it to display "1 of 5" through "5 of 5". I am using Sections.HeadersFooters.LinkToPrevious(false). I've tried changing the parameter to true, and specifying the HeaderFooterType, but those aren't successful either.


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words 9.1.0. Please make sure that PageSetup.RestartPageNumbering property is not set during processing your documents:

Also, could you please attach your documents and a simple code here for testing?

Best regards,

Try turning one of the docs landscape while leaving the other portrait. Looks like this is the cause. Is there a way to maintain the pages with both layouts in the document?


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. But I still cannot reproduce the problem on my side. I use the following code for testing:

Document doc1 = new Document("1.doc");

Document doc2 = new Document("2.doc");

Document doc3 = new Document("3.doc");

doc1.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);

doc1.AppendDocument(doc3, ImportFormatMode.KeepSourceFormatting);


I attached my input and output documents here.

Could you please attach your documents and the code which will allow me to reproduce the problem on my side?

Best regards,

Please note that I'm actually using 9.0.0. Here is the code I use. Attached are the two source documents, Doc1.docx and Doc2.docx as well as the resulting document, Out.docx. The footer displays "1 of 1" and "2 of 2".

MemoryStream strmForm1 = GetDocStream(DocPath + "Doc1.docx");

Document docForm1 = new Document(strmForm1);

MemoryStream strmForm2 = GetDocStream(DocPath + "Doc2.docx");

Document docForm2 = new Document(strmForm2);

docForm1.AppendDocument(docForm2, ImportFormatMode.KeepSourceFormatting);

docForm1.Save("Out.docx", SaveFormat.Docx, SaveType.OpenInApplication, HttpContext.Current.Response);


public MemoryStream GetDocStream(string url)


System.Net.WebRequest docRequest = System.Net.WebRequest.Create(url);

System.Net.WebResponse docResponse = docRequest.GetResponse();

byte[] responseData = new byte[docResponse.ContentLength];

int bytesRead = 0;

while (bytesRead < docResponse.ContentLength)


int bytesToRead = (int)docResponse.ContentLength - bytesRead;

bytesRead += docResponse.GetResponseStream().Read(responseData, bytesRead, bytesToRead);



MemoryStream ms = new MemoryStream(responseData);

return ms;



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. It seems this is not Aspose.Words issue; I think this is MS Word issue. I know that sometimes such problem occurs with the first page header/footer. For some reason MS Word does not update NUMPAGES fields there. In case of using primary header/footer this problem never occurs.

I think information provided in the following thread could be useful for you:

Best regards,