我正在尝试导出一个word文档,这大约是2-3页。我使用了两张图片,一张是页眉,另一张是页脚。
问题是页眉和页脚图像只出现在首页,而不出现在其他两页。
目前我使用的是docx4j 3.2.1。如何解决此问题?
这是我的代码:
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);
}发布于 2015-07-13 20:35:52
不要使用footerReference.setType(HdrFtrRef.FIRST)。
我建议您使用Word创建一个您想要设置的文档,然后将w:sectPr (和相关部分)复制到其中。
你可以使用docx4j webapp从你的示例文档中生成代码。
https://stackoverflow.com/questions/31383007
复制相似问题