I want to append the text "continued on the following page" in the footer if there is next page. Also , I want to append the text "continued from the previous page.." in the header of the page if it has a previous page.
The following is the footer code I am using. This gives the same footer in all the pages. Could you please suggest me , how can I achieve the customized footer /header.
BTW , I tried footerReference.setType(HdrFtrRef.DEFAULT); changing the type to First and others, but that too went in vain. Thanks !!!
- Code: Select all
public void addFooter(WordprocessingMLPackage wordMLPackage) throws InvalidFormatException, JAXBException {
FooterPart footerPart = new FooterPart();
Relationship rel = wordMLPackage.getMainDocumentPart().addTargetPart(footerPart);
String ftrXml = "<w:ftr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">"
+ "<w:p>"
+ "<w:pPr>"
+ "<w:pStyle w:val=\"Footer\"/>"
+ "<w:jc w:val=\"right\"/>"
+ "</w:pPr>"
+ "<w:fldSimple w:instr=\" PAGE \\* MERGEFORMAT \">"
+ "<w:r>"
+ "<w:rPr>"
+ "<w:noProof/>"
+ "</w:rPr>"
+ "</w:r>"
+ "</w:fldSimple>"
+ "</w:p>"
+ "</w:ftr>";
Ftr ftr = (Ftr) XmlUtils.unmarshalString(ftrXml);
footerPart.setJaxbElement(ftr);
// Now Create foooter reference
ObjectFactory objectFactory = new ObjectFactory();
List<SectionWrapper> sections = wordMLPackage.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr == null) {
sectPr = objectFactory.createSectPr();
wordMLPackage.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = objectFactory.createFooterReference();
footerReference.setId(rel.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}