问题描述
我有一个word文件,我想计算其中的页数.
I got a word file and I want to count how many pages are in it.
该文件已使用Docx4Java创建.
The file has been created with Docx4Java.
有人做过吗?
谢谢!
推荐答案
docx4j没有页面布局模型,因此它不能告诉您页面数.
docx4j doesn't have a page layout model, so it can't tell you a page count.
您可以使用FOP的页面布局模型来获得大概的页面数.docx4j的PDF输出现在支持"2次通过"生成:
You can get an approximate page count by using FOP's page layout model. docx4j's PDF output now supports a "2 pass" generation:
- 第一遍计算页数
- 第二遍生成pdf
请参见 https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/convert/out/fo/AbstractPlaceholderLookup.java 和 https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/convert/out/fo/ApacheFORenderer.java
因此,通过第一遍会(大约)为您提供您想要的东西.它使用org.apache.fop.apps.FormattingResults来记录页面顺序或整个文档中的页面数.
So doing the first pass would give you (approximately) what you want. This uses org.apache.fop.apps.FormattingResults which records the number of pages in a page sequence, or in the document as a whole.
另一种方法可能是使用LibreOffice/OpenOffice(或Microsoft Word).
An alternative approach might be to use LibreOffice/OpenOffice (or Microsoft Word, for that matter).
这篇关于计算docx文档中的页面数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!