The Header align is wrong after attach word

the “main” word like

but after attached cover word, it looks like:

1.docx (175.8 KB)

out.docx (129.3 KB)

cover.docx (19.3 KB)

the result the align of header is left from center.

Here is my code:

String path = "C:\\Users\\z_jia\\Desktop\\a\\";
Document main = new Document(path + "1.docx");
Document cover = new Document(path + "cover.docx");
cover.appendDocument(main, ImportFormatMode.KEEP_SOURCE_FORMATTING);

var word = cover;
var sections = word.getSections();
if (sections.getCount() > 1)
{
    var section1 = sections.get(0);
    section1.getPageSetup().setRestartPageNumbering(false);
    section1.getHeadersFooters().clear();
    var section2 = sections.get(1);
    var headersFooters2 = section2.getHeadersFooters();
    for (int i = 0; i < headersFooters2.getCount(); i++)
    {
        var headerFooter2 = headersFooters2.get(i);
        var clonedHeaderFooter = word.importNode(headerFooter2, true);
        section1.getHeadersFooters().add(clonedHeaderFooter);
    }

    section1.getPageSetup().setRestartPageNumbering(false);
    section2.getPageSetup().setRestartPageNumbering(false);
}

cover.save(path + "out.docx");

@GusGus
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28074

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@GusGus We have completed analyzing the issue. We are going to close this issue as Not a Bug. The behavior in Aspose.Words and Word is the same. We’ve attached ms.docx (124.8 KB) for your reference.
The reason of the behavior is different alignment in Normal style of the input documents. And Word doesn’t applies styles difference in Headers of the appended document. Aspose.Words behaves the same as Word by default.

However, there are number of options in Aspose.Words to solve the problem. You can use either ImportFormatOptions.IgnoreHeaderFooter = false, or ImportFormatOptions.ForceCopyStyles = true to achieve desired result.
For example:

Document cover = new Document(@"C:\Temp\cover.docx");
Document doc = new Document(@"C:\Temp\in.docx");

// Add this option.
ImportFormatOptions options = new ImportFormatOptions();
options.IgnoreHeaderFooter = false;

cover.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting, options);
cover.Save(@"C:\Temp\out.docx");