- Code: Select all
FooterPart footerPart = new FooterPart();
footerPart.setPackage(wordMLPackage);
footerPart.setRelationshipType(Namespaces.FOOTER);
P paragrafo = factory.createP();
PPr ppr = factory.createPPr();
Jc jc = factory.createJc();
jc.setVal(JcEnumeration.RIGHT);
ppr.setJc(jc);
PStyle pStyle = new PStyle();
pStyle.setVal("Footer");
ppr.setPStyle(pStyle);
ParaRPr rPrPageNumber = factory.createParaRPr();
RStyle rStyle = factory.createRStyle();
rStyle.setVal("PageNumber");
rPrPageNumber.setRStyle(rStyle);
ppr.setRPr(rPrPageNumber);
paragrafo.setPPr(ppr);
R r = factory.createR();
CTSimpleField ctSimple = factory.createCTSimpleField();
ctSimple.setInstr("PAGE");
JAXBElement<CTSimpleField> fldSimple = factory.createPFldSimple(ctSimple);
R rSimple = factory.createR();
RPr rprSimple = factory.createRPr();
rprSimple.setNoProof(new BooleanDefaultTrue());
Text tSimple = factory.createText();
tSimple.setValue("1");
rSimple.setRPr(rprSimple);
rSimple.getContent().add(tSimple);
fldSimple.getValue().getContent().add(rSimple);
r.getContent().add(fldSimple);
paragrafo.getContent().add(r);
footerPart.getContent().add(paragrafo);
P paragrafo2 = factory.createP();
PPr ppr2 = factory.createPPr();
Ind ind = factory.createPPrBaseInd();
ind.setRight(BigInteger.valueOf(360));
ppr2.setPStyle(pStyle);
ppr2.setInd(ind);
paragrafo2.setPPr(ppr2);
footerPart.getContent().add(paragrafo2);
Relationship addTargetPart = wordMLPackage.getMainDocumentPart().addTargetPart(footerPart);
//Add footer reference
FooterReference ft = factory.createFooterReference();
ft.setType(HdrFtrRef.DEFAULT);
ft.setId(addTargetPart.getId());
SectPr sectPr = factory.createSectPr();
sectPr.getEGHdrFtrReferences().add(ft);
ft.setParent(sectPr);
wordMLPackage.getMainDocumentPart().addObject(sectPr);
When generated in docx format work as expected, but when I convert to pdf using FO the footer with the page number doesn't appear