- Code: Select all
FooterPart footerPart = new FooterPart();
footerPart.setPackage(wordMLPackage);
footerPart.getContent().add(createStampP()); // predefined paragraph with a sample text
Relationship relationship = wordMLPackage.getMainDocumentPart().addTargetPart(footerPart);
SectPr sectPr = sectionWrapper.getSectPr();
if (sectPr == null) {
sectPr = factory.createSectPr();
wordMLPackage.getMainDocumentPart().addObject(sectPr);
sectionWrapper.setSectPr(sectPr);
}
FooterReference footerReference = factory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(hdrFtrRef); // DEFAULT
sectPr.getEGHdrFtrReferences().add(footerReference);
It is based on this example http://www.docx4java.org/svn/docx4j/trunk/docx4j/src/main/java/org/docx4j/samples/HeaderFooterCreate.java
Now here's the expected outcome:
That's a default footer created through LibreOffice.
And here's the actual outcome (programmatically created footer):
Ignore the different font size and family, I only care about respecting the default margins in this case.
From what I've found out, the bottom page margin has changed to 0 after the footer creation, not sure why. I want the created footer to respect the page's original margins and appear as in first screenshot (and sorta respect the default footer parameters as if it was made in LibreOffice). Any tips and advices on how to achieve that are welcomed.