使用DOCX4J转换为PDF时,页面编号会丢失

发布于 2025-02-03 04:04:04 字数 975 浏览 3 评论 0原文

IM构建一个API,使用DOCX4J LIBARY在Word文件(.DOCX)和PDF中转换XHTML文件。 此时,该应用程序几乎可以很好地处理一些格式的问题。

我使用此代码段将CTSimpleFields添加到我的Word文档中:

 CTSimpleField currentPageNumber = factory.createCTSimpleField();
 currentPageNumber.setInstr(" PAGE \\* Arabic  \\* MERGEFORMAT ");
 CTSimpleField totalPageCount = factory.createCTSimpleField();
 totalPageCount.setInstr("NUMPAGES  \\* Arabic  \\* MERGEFORMAT");

如果将文档保存为DOCX

wordZipFile.save(getOutputStream());

Word输出, 则可以很好地工作。

但是,当我尝试使用此片段将WordMlPackage转换为PDF时:

FieldUpdater updater = new FieldUpdater(this.wordZipFile);
updater.update(true);
Docx4J.toPDF(this.wordZipFile,this.getOutputStream());

输出PDF文件中缺少页码。

pdf输出

是否有人想知道如何解决这个问题?

Im Building a API to convert XHtml Files in Word files (.docx) and in PDF, using the Docx4j Libary.
At this Moment the Application works almost well with a few little (i think) formatting issues.

I add CTSimpleFields to my Word document using this code snippet:

 CTSimpleField currentPageNumber = factory.createCTSimpleField();
 currentPageNumber.setInstr(" PAGE \\* Arabic  \\* MERGEFORMAT ");
 CTSimpleField totalPageCount = factory.createCTSimpleField();
 totalPageCount.setInstr("NUMPAGES  \\* Arabic  \\* MERGEFORMAT");

This works well if the document is saved as docx

wordZipFile.save(getOutputStream());

Word Output

But when i try to convert the WordMLPackage to PDF using this snippet:

FieldUpdater updater = new FieldUpdater(this.wordZipFile);
updater.update(true);
Docx4J.toPDF(this.wordZipFile,this.getOutputStream());

The page numbering is missing in the output PDF file.

PDF Output

Has somebody an idea how to workaround for this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文