Document.ImportNode() messes up footer formatting

Hi -
I have the following code used to merge several Word documents into one:

public static byte[] ConvertMultipleDocs2SingleDoc(params Stream[] wordDocStreams)
{
    byte[] result = null;
    SaveFormat saveFormat = SaveFormat.Doc;
    try
    {
        if (wordDocStreams != null && wordDocStreams.Length > 0)
        {
            License lic = new License();
            lic.SetLicense("TestEnvironmentAsposeWords.Aspose.Words.lic");
            DocumentBuilder builder = new DocumentBuilder();
            builder.Document.Sections.Clear();
            foreach (Stream stream in wordDocStreams)
            {
                Document document = new Document(stream);
                document.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
                foreach (Section section in document)
                {
                    section.PageSetup.SectionStart = SectionStart.NewPage;
                    section.HeadersFooters.LinkToPrevious(false);
                    Section newSection = (Section)builder.Document.ImportNode(section, true, ImportFormatMode.KeepSourceFormatting);
                    builder.Document.Sections.Add(newSection);
                }
            }
            using (MemoryStream ms = new MemoryStream())
            {
                SaveOptions so = SaveOptions.CreateSaveOptions(saveFormat);
                so.PrettyFormat = true;
                builder.Document.Save(ms, so);
                result = ms.ToArray();
            }
        }
    }
    catch (Exception ex)
    {
        throw new ApplicationException("Error concatenating multiple documents to a single Word file!", ex);
    }
    return result;
}

The footer of the original document before the merge looks like this:
(see attachment: Aspose footer error INPUT.png)
But the output looks like this:
(see attachment: Aspose footer error OUTPUT.png)
Any ideas what might have happened?

Hi Anton,

Thanks for your query. It would be great if you please share your documents for investigation purposes.

Thanks Tahir!
I’ve attached my sample document and edited my code a bit so it’d be easier for you to troubleshoot.

Hi Anton,

Thanks for sharing the code and document. I have tested the scenario and have not found any issue with output document while using latest version ofAspose.Words for .NET. Please use the latest version of Aspose.Words for .NET. I have used ConvertMultipleDocs2SingleDoc method as shown below. Please find the output document in attachment.

Stream stream = File.OpenRead(MyDir + "SampleFile.doc");
Stream stream2 = File.OpenRead(MyDir + "in.docx");
Stream[] array = { stream, stream2 };
byte[] b = ConvertMultipleDocs2SingleDoc(array);

Please let us know if you have any more queries.