XWPFDocument - getPageCount(XWPFDocument - getPageCount)_电脑培训 - poi 获取总页数

XWPFDocument - getPageCount(XWPFDocument - getPageCount)

对于旧的Microsoft格式(.doc),APACHE POI使用了HWPFDocument。 要知道此对象的页数,我只需要:

 HWPFDocument document = new HWPFDocument(new FileInputStream(file.getAbsolutePath()));
            System.out.println(document.getSummaryInformation().getPageCount());

现在,我想对XWPFDocument(对于.docx)执行相同操作,但此方法不存在。

我试过了:

XWPFWordExtractor extractor = new XWPFWordExtractor(document);

并查看它是否有类似于getPageCount()但我没有找到任何东西。

For old Microsoft formats (.doc) APACHE POI used HWPFDocument. To know the number of pages for this object, I just needed to do:

 HWPFDocument document = new HWPFDocument(new FileInputStream(file.getAbsolutePath()));
            System.out.println(document.getSummaryInformation().getPageCount());

Now, I want to do the same to XWPFDocument (for .docx), but this method do not exist.

I tried:

XWPFWordExtractor extractor = new XWPFWordExtractor(document);

and see if it has something similar to getPageCount() but i did not found anything.

更新时间:2022-12-16 18:12

最满意答案

我无法测试它,但我建议试试这个:

XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(DocFilePath));

int numPages = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();

https://poi.apache.org/apidocs/org/apache/poi/POIXMLProperties.ExtendedProperties.html

I cannot test it but I suggest try this:

XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(DocFilePath));

int numPages = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();

https://poi.apache.org/apidocs/org/apache/poi/POIXMLProperties.ExtendedProperties.html

相关问答

更多


原网址: 访问
创建于: 2023-05-08 17:26:26
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论