Document format changed when inserting header



we noticed an issue with header files, if they have a different format than the original file. In our product our customer can define a global header file (usually A4) which will be inserted in their documents. If the document itself has an other format (for example A3), the result document will shrink to the format of the header file (A4) and images may get cropped.

original document is A3.
global header file is A4

After inserting the header into the document and saving it again, the document will be A4 (tested with docx and pdf as save format). Exporting as pdf without inserting a header file behaves correctly.

You may reproduce the issue with the following code we use and the documents attached to the ticket:

 var lic = new License();

            var doc = new Document(@"S:\a3.docx");
            var builder = new DocumentBuilder(doc);
            var header = builder.CurrentSection.HeadersFooters[HeaderFooterType.HeaderPrimary];
            if (header == null)
                header = new HeaderFooter(doc, HeaderFooterType.HeaderPrimary);

            var headerDoc = new Document(@"S:\header.doc");
            headerDoc.FirstSection.PageSetup.Orientation = doc.FirstSection.PageSetup.Orientation;
            builder.InsertDocument(headerDoc, ImportFormatMode.KeepSourceFormatting); // KeepSourceFormatting, KeepDifferentStyles, UseDestinationStyles all produce the error
            builder.CurrentParagraph.Remove(); // remove additional line break at end


Files in the example:
a3.docx -> original A3 file
header.doc -> global A4 header file
out.pdf -> generated pdf with aspose and above source code
out_word.pdf -> original file converted to pdf with MS Word
out_word_header.pdf -> manually copy pasted all content of header.doc into the header section of a3.docx via word and converted to pdf with MS Word.

As you can see, the PDF genrated with Aspose are A4 instead of A3 and the image in the document becomes cropped. (588.3 KB)

Kind Regards,



We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-18875. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.



We have good news for you i.e. WORDSNET-18875 has now been resolved. The fix of this issue is included in the 19.8 version of Aspose.Words for .NET . Please upgrade to the latest version. Hope, this helps.


The issues you have found earlier (filed as WORDSNET-18875) have been fixed in this Aspose.Words for .NET 19.8 update and this Aspose.Words for Java 19.8 update.