Я реализовал библиотеку Apache POI для количества страниц страниц Doc, но при загрузке Google Doc в виде файла .docx он показывает ноль.
Редактировать: Мой код выглядит следующим образом
public Integer getPagesCount(byte[] docBytes, String type)
throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(docBytes);
String lowerFilePath = type.toLowerCase();
if (lowerFilePath.equals("docx")) {
@SuppressWarnings("resource")
XWPFDocument docx = new XWPFDocument(in);
return docx.getProperties().getExtendedProperties()
.getUnderlyingProperties().getPages();
} else if (lowerFilePath.equals("doc")) {
@SuppressWarnings("resource")
HWPFDocument wordDoc = new HWPFDocument(in);
return wordDoc.getSummaryInformation().getPageCount();
} else if (lowerFilePath.equals("ppt")) {
HSLFSlideShow document = new HSLFSlideShow(in);
return document.getSlides().size();
} else if (lowerFilePath.equals("pptx")) {
@SuppressWarnings("resource")
XMLSlideShow xslideShow = new XMLSlideShow(in);
return xslideShow.getSlides().size();
} else if (lowerFilePath.equals("pdf")) {
PDDocument doc = PDDocument.load(in);
return doc.getNumberOfPages();
}
return 0;
}