3

My problem is the following:

There are some huge PDF files (>500MB) and I want to find their page count, using JAVA. If I use itext or pdfbox, I have to wait until it reads the whole file and most of the times this fails, because of the large size of the file or it just takes a lot of time.

So, I would like to know if there is any quick and efficient way to find the page count of a PDF file.

user3519936
  • 102
  • 7

1 Answers1

2

Possible duplicate? Page count of Pdf with Java

and from that's post, Mark Storer's answer:

The itext API underwent a little overhaul. Now (in version 5.4.x) the correct way to use it is to pass through java.io.RandomAccessFile:

int efficientPDFPageCount(File file) {
     RandomAccessFile raf = new RandomAccessFile(file, "r");
     RandomAccessFileOrArray pdfFile = new RandomAccessFileOrArray(
          new RandomAccessSourceFactory().createSource(raf));
     PdfReader reader = new PdfReader(pdfFile, new byte[0]);
     int pages = reader.getNumberOfPages();
     reader.close();
     return pages;
}
MohannadNaj
  • 1,029
  • 13
  • 12
  • @user3519936 Please share the file in question and indicate an acceptable amount of time. – mkl Jun 30 '16 at 13:00