XWPFDocument - getPageCount
For older Microsoft (.doc) APACHE POI formats, HWPFDocument is used. To find out the number of pages for this object, I just had to do:
HWPFDocument document = new HWPFDocument(new FileInputStream(file.getAbsolutePath()));
System.out.println(document.getSummaryInformation().getPageCount());
Now I want to do the same with XWPFDocument (for .docx) but this method doesn't exist.
I tried:
XWPFWordExtractor extractor = new XWPFWordExtractor(document);
and see if it has something similar to getPageCount (), but I couldn't find anything.
+3
source to share
2 answers
I can't verify this, but I suggest trying 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
+3
source to share