Alternative way to find no. of pages inside PDF?

Kurt Pfeifle kurt.pfeifle at infotec.com
Sat Jun 14 07:21:08 PDT 2008


I know I can use pdfinfo from the xpdf package like this

   pdfinfo some.pdf|grep Pages:|awk '{print $2}'

in order to find out how many pages are in a given PDF, and get the result very fast. But what if I do not have a "pdfinfo" utility available (Ghostscript is available...)

Does anybody of you know a different (fast enough) method to know the number of pages inside a PDF?

Using Ghostscript to render the PDF and then count pages is way too slow... I know Ghostscript somehow has access to the info, because I can run

   gs \
      -dBATCH \
      -dNOPAUSE \
      -sDEVICE=nullpage \
      -dFirstPage=9999 \
      -dLastPage=9999 \
      a-211-page.pdf

does give me this output :

  [....]
  Requested FirstPage is greater than the number of pages in the file: 211
     No pages will be processed (FirstPage > LastPage).

Which other way than running the above command, grepping for that line and awk-printing the final number (which is 4-5 times slower than using pdfinfo) can you think of?

Cheers,
Kurt




More information about the cups mailing list