now I can create two footers by using the following code:
- Code: Select all
public static 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:rsidR=\"00CD3E70\" w:rsidRDefault=\"00ED630A\" w:rsidP=\"00AB75CC\">"
+ "<w:pPr><w:tabs><w:tab w:val=\"right\" w:pos=\"9360\"/></w:tabs><w:rPr><w:lang w:eastAsia=\"zh-CN\"/></w:rPr></w:pPr>"
+ "<w:r><w:t>111</w:t></w:r>"
+ "<w:r w:rsidR=\"00AB75CC\"><w:tab/></w:r>"
+ "<w:r w:rsidR=\"00AB75CC\"><w:rPr><w:rFonts w:hint=\"eastAsia\"/><w:lang w:eastAsia=\"zh-CN\"/></w:rPr><w:t>222</w:t></w:r>"
+ "</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);
}
the responding result is :
- footers.png (878 Bytes) Viewed 2000 times
however, I want to replace the first footer with a logo, e.g:
- logo_footer.png (2.1 KiB) Viewed 2000 times
how can I modify the above code to get this, thanks!