Document format changed when inserting header


#1

Hi,

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.

Example:
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();
            lic.SetLicense(@"S:\Aspose.Total.lic");

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

            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

            doc.Save(@"S:\out.pdf");

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.

example.zip (588.3 KB)

Kind Regards,
Daniel


#2

@Serraniel,

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.