Losing Headers/Footers on Append

I’ve noticed that if I append a document that has a header/footer to one that doesn’t, the header/footer isn’t appended. Is there a work around for this? I’ve attached the files I am using for testing. Below is the code I currently have:

Document doc1 = new Document(@"C:\Projects\Test\Alabama Surplus Lines Tax Template.doc");
Document doc2 = new Document(@"C:\Projects\Test\CA 01 97 03 12.doc");

doc2.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
doc1.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);
doc1.Save(@"Test.doc");

Hi Kathryn,

Thanks for your inquiry. I have tested the scenario using latest version of Aspose.Words for .NET 14.12.0 and have not found the shared issue. Please use Aspose.Words for .NET 14.12.0. I have attached the output document with this post for your kind reference.

Tahir,
The output document you posted is the exact same as the output I’ve generated. Please look at the last 2 pages. The original document has a header and footer. The header and footer are missing on pages 2 & 3 of the output document.

Hi Kathryn,

Thanks for your inquiry. Could you please share the screenshot of output document here for our reference? I have not found this issue in output document. The header/footer are visible in output document. Please check the attached screenshot for detail.

Apologies! I see from your screen shot that I have to change my view mode to see them. Is there anything that can be done about the page numbers though? In the output, they are “2 of 3” and “3 of 3” instead of “1 of 2” and “2 of 2”.

Hi Kathryn,

Thanks for your inquiry.

Please use PageSetup.RestartPageNumbering property to restart page numbering at the beginning of the section. See the highlighted code snippet below.

Your document contains NUMPAGES field. Please replace this field with SECTIONPAGES field to get the required output.

Document doc = new Document(MyDir + "Sample_document.doc");
Document doc1 = new Document(MyDir + "Alabama+Surplus+Lines+Tax+Template.doc");
Document doc2 = new Document(MyDir + "CA+01+97+03+12.doc");
doc2.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
doc2.FirstSection.PageSetup.RestartPageNumbering = true;
doc1.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);
doc1.Save(MyDir + "Out.doc");