Page 1 of 1

Header missing in PDF output

PostPosted: Fri Oct 19, 2012 8:33 am
by mgrela
Hi,

I'm making a header in my document using the code from the example http://www.docx4java.org/trac/docx4j/br ... reate.java with the following code added in main():

wordMLPackage.save(new File(filename + ".docx"));
// mainDocumentPart.marshal(new FileOutputStream(new File(System
// .getProperty("user.dir"), "headerfooter.xml")));

// PDF export starts here
Mapper font_mapper = new IdentityPlusMapper();
wordMLPackage.setFontMapper(font_mapper);

org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);

c.output(new java.io.FileOutputStream(filename + ".pdf"), new org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings());

System.out.println("done");

In the resulting PDF the header image is not present. What to do to generate a proper header ?

Re: Header missing in PDF output

PostPosted: Mon Oct 22, 2012 12:06 am
by jason
Actually it works for me already (2.8.1).

Which docx4j are you using? What image format?

Please post your docx and I will take a look.

Re: Header missing in PDF output

PostPosted: Tue Oct 23, 2012 1:24 am
by mgrela
Hi,

I'm running docx-2.8.1 downloaded from your webside on a Mac OS X 10.7.5.

I'm posting the code I've been running, the docx and PDF files generated. The logo is a jpeg image. I have also attached the output of the run. Hope this helps.

Re: Header missing in PDF output

PostPosted: Tue Oct 23, 2012 3:49 am
by jason
Thanks for the clear description of the issue :-)

The problem is that docx4j maintains an internal model of the sections in your docx, including the headers/footers in each section.

Adding a header/footer as your code does does not update the model, so when the PDF is generated, docx4j does not know there is a header present.

Just fixed as https://github.com/plutext/docx4j/commi ... 1f5d93e0a8

Re: Header missing in PDF output

PostPosted: Tue Oct 23, 2012 7:25 am
by mgrela
Compiled new version and it works ! Thanks a lot.

Re: Header missing in PDF output

PostPosted: Thu Nov 15, 2012 7:46 am
by tchydock
Jason,

You mentioned that the way that mgrela was creating headers/footers does not update the model...Can you give a code example of how one should create headers/footers so that they are included when generating PDF?

Thank you.

Re: Header missing in PDF output

PostPosted: Tue Nov 20, 2012 2:45 pm
by jason
As from https://github.com/plutext/docx4j/commi ... 462ba3c233 this is done automatically before generating a PDF.

Prior to that commit, you should invoke wordMLPackage.getDocumentModel().refresh()

Re: Header missing in PDF output

PostPosted: Thu Nov 22, 2012 7:01 am
by tchydock
Thank you so much Jason! That worked perfectly.