当前位置: 动力学知识库 > 问答 > 编程问答 >

How to create a PDF document with header from a template with docx4j?

问题描述:

I want to create a document from an existing Word 2010 document and convert it to PDF using docx4j 3.1.0. I've built upon the sample in

https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/ConvertOutPDF.java

The Word document already contains a header with text and an image that I do not modify in my processing. The resulting PDF document, however, doesn't contain the header.

Is this someting that is supposed to work? If yes: how can I find out what I am missing?

网友答案:

Yes, if you can see the header when you "save as PDF" in Word, then you should also see the header in docx4j's PDF output.

To have it fixed, we'll need to see the docx.

网友答案:

Just for the curious reader: the specific cause for the missing header turned out to be a wrong approach of setting page margins on the document. Instead of modifiying the existing settings via body.getSectPr().getPgMar() (or even simpler: setting it in the template right away), the code created new PageDimensions and set a new SectPtr on the body, thereby somehow overwriting or removing the header.

分享给朋友:
您可能感兴趣的文章:
随机阅读: