0

I'm trying to export a word document which is about 2-3 pages. I use 2 images, one for header and another one for footer.

The problem is the header and footer images only appear on front page but not on the other 2 pages.

Currently I'm using docx4j 3.2.1. How can I fix this issue?

This is my code:

if(footerFileFlag){
    java.io.InputStream footerImage = new java.io.FileInputStream(footerFilePath);

    FooterPart footerPart = new FooterPart();
    Relationship footerRel = wordMLPackage.getMainDocumentPart().addTargetPart(footerPart);
    Ftr ftr = objectFactory.createFtr();

    ftr.getContent().add(newImage(wordMLPackage,footerPart, BufferUtil.getBytesFromInputStream(footerImage), "footerImage", "alttext", 1, 2));
    footerPart.setJaxbElement(ftr);

    FooterReference footerReference = objectFactory.createFooterReference();
    footerReference.setId(footerRel.getId());
    footerReference.setType(HdrFtrRef.FIRST);
    sectPr.getEGHdrFtrReferences().add(footerReference);
    footerPart.setJaxbElement(ftr);
}
Trung Bún
  • 1,117
  • 5
  • 22
  • 47

1 Answers1

0

Don't use footerReference.setType(HdrFtrRef.FIRST).

I suggest you use Word to create a document set up as you want, then copy the w:sectPr (and associated parts) in that.

You can use the docx4j webapp to generatecode from your sample docx.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • Thank Jason. What are possible values for `setType()` method? And also, this docx4j package is used to generate a docx file for an web-based application so it would be impossible to create a document setup as I want. – Trung Bún Jul 13 '15 at 13:25