I'm trying to count pages from a word document with java.
This is my actual code, i'm using the Apache POI libraries
String path1 = "E:/iugkh";
File f = new File(path1);
File[] files = f.listFiles();
int pagesCount = 0;
for (int i = 0; i < files.length; i++) {
POIFSFileSystem fis = new POIFSFileSystem(new FileInputStream(files[i]));
HWPFDocument wdDoc = new HWPFDocument(fis);
int pagesNo = wdDoc.getSummaryInformation().getPageCount();
pagesCount += pagesNo;
System.out.println(files[i].getName()+":\t"+pagesNo);
}
The output is:
ten.doc: 1
twelve.doc: 1
nine.doc: 1
one.doc: 1
eight.doc: 1
4teen.doc: 1
5teen.doc: 1
six.doc: 1
seven.doc: 1
And this is not what i expected, as the first three documents' page length is 4 and the other are from 1 to 5 pages long.
What am i missing?
Do i have to use another library to count the pages correctly?
Thanks in advance