java - Counting pages in a Word document -


i'm trying count pages word document java.

this actual code, i'm using apache poi libraries

string path1 = "e:/iugkh"; file f = new file(path1); file[] files = f.listfiles(); int pagescount = 0; (int = 0; < 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 not expected, first 3 documents' page length 4 , other 1 5 pages long.

what missing?

do have use library count pages correctly?

thanks in advance

this may you. counts number of form feeds (sometimes used separate pages), i'm not sure if it's gonna work documents (i guess not).

wordextractor extractor = new wordextractor(document); string[] paragraphs = extractor.getparagraphtext();  int pagecount = 1; (int = 0; < paragraphs.length; ++i) {     if (paragraphs[i].indexof("\f") >= 0) {         ++pagecount;     } }  system.out.println(pagecount); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -