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()));


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.


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();





From the XWPFWordExtractor, you can get the number of pages by doing the following:

XWPFWordExtractor extractor = new XWPFWordExtractor(document);
int pageCount = extractor.getExtendedProperties().getPages();


Details like this and this bit Apache POI javadocs



All Articles