对于旧的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()的东西,但是我什么也没找到。
我无法对其进行测试,但我建议尝试以下操作:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句