Merge two documents with Even/Odd Header Footers

I am generating a merged document on the basis of two documents using Aspose.Words Document class.

Source Document is having multiple pages with Even and Odd Header footers and another document is empty with no header/footer.

My requirement is to merge source document with the blank document with even and odd header in the proper place in the final document but somehow merged document is having only odd header and footers.
Below is the source code and documents. Please have a look and suggest changes in order to achieve the required functionality.

string originalDocumentPath = @“D:\originaldocument.docx”;
string blankDocumentPath= @“D:\blankdocument.docx”;
string mergedDocumentPath = @“D:\mergeddocument.docx”;

        Aspose.Words.Document originalDoc = new Aspose.Words.Document(originalDocumentPath);
        Aspose.Words.Document mergedDoc = new Aspose.Words.Document(blankDocumentPath);

        mergedDoc.AppendDocument(originalDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting);
        mergedDoc.Save(mergedDocumentPath, Aspose.Words.SaveFormat.Docx);

Here are 3 documents within zip file.
documents.zip (46.7 KB)


This Topic is created by sohail.aspose using the Email to Topic plugin.

@mehtabcompunnel,

You can manually copy all Headers and Footers from last Section to the previous Section to get the desired results:

Document originalDoc = new Document("D:\\temp\\Documents\\originaldocument.docx");
Document mergedDoc = new Document("D:\\temp\\Documents\\BlankDocument.docx");

mergedDoc.AppendDocument(originalDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting);

mergedDoc.FirstSection.PageSetup.OddAndEvenPagesHeaderFooter = true;
foreach(HeaderFooter hf in mergedDoc.LastSection.HeadersFooters)
{
    mergedDoc.FirstSection.HeadersFooters.Add(hf.Clone(true));
}

mergedDoc.Save("D:\\temp\\Documents\\18.7.docx");

A post was split to a new topic: Working with headers/footers after AppendDocument