Aspose-pdf generates other header than Aspose-Word

Hello everybody,

we currently have the problem that saving as PDF sets headers incorrect in some constellations. If the same document is saved as a Word file, the header is set correctly. Here is a minimal example of what we use for testing (please adjust the paths in the code so that they can be found):

public class AsposeTest {
    public static void main(String[] args) throws Exception {
        Document fails = new Document(new FileInputStream(new File(AsposeTest.class.getResource("/checkliste.doc").getPath())));
        Document template = new Document(new FileInputStream(new File(AsposeTest.class.getResource("/orgavision_schablone_original.docx").getPath())));

        replaceHeadersFooters(fails, template);
        File pdfResult = new File("./failed.pdf");
        File docxResult = new File("./worked.docx");

        SaveOptions docxSaveOptions = new OoxmlSaveOptions();
        docxSaveOptions.setSaveFormat(SaveFormat.DOCX);

        fails.save(new FileOutputStream(pdfResult), new PdfSaveOptions());
        fails.save(new FileOutputStream(docxResult), docxSaveOptions);
    }

    private static void replaceHeadersFooters(Document document, Document template) {
        final NodeImporter importer = new NodeImporter(template, document, ImportFormatMode.KEEP_SOURCE_FORMATTING);
        final HeaderFooterCollection templateCol = template.getFirstSection().getHeadersFooters();
        boolean firstSection = true;
        for (final Section section : document.getSections()) {
            final HeaderFooterCollection sectionCol = section.getHeadersFooters();
            for (int i = 0; i < templateCol.getCount(); i++) {
                final HeaderFooter templateHF = templateCol.get(i);
                final HeaderFooter sectionHF = sectionCol.getByHeaderFooterType(templateHF.getHeaderFooterType());
                if (sectionHF != null) {
                    sectionHF.remove();
                }
                if (firstSection) {
                    sectionCol.add((importer.importNode(templateHF, true)));
                }
            }
            firstSection = false;
        }
    }
}

files.zip (42.9 KB)

It should look like worked.docx. failed.pdf is the wrong result.
I attached the template and the document.

We use the latest version of aspose-words (19.1) and aspose-pdf (18.11).

Can you tell us where the problem is?
If you need more information, just let me know.

Thank you and best regards

@orgavision,

We tested the scenario and 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-18012. 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.

The issues you have found earlier (filed as WORDSNET-18012) have been fixed in this Aspose.Words for Java 23.10 update.

1 Like