Alternative way to find no. of pages inside PDF?

James Cloos cloos at jhcloos.com
Tue Jun 17 00:28:53 PDT 2008


pdfinfo gets the number of pages by counting them as it traverses the
object hierarchy.

Looking at some of the postscript file in gs's lib dir, it looks like
the ps function pdfpagecount will do what you want.

Specifically, something like this untested code:

    %!
    % run using:
    % gs -dNODISPLAY -sPDFname=pdffilename pdfpagecount.ps
    systemdict /.setsafe known { .setsafe } if
    GS_PDF_ProcSet begin
    pdfdict begin
    /PDFname (r) file
    pdfopen begin
    (%stdout) (w) file dup dup
    pdfpagecount 10 string cvs
    writestring
    (\n) writestring
    flushfile
    quit

(Note that gs prints its copyright info to stdout, you may want
to pipe it to tail -1 or grep for ^[0-9] or some such.)

-JimC
-- 
James Cloos <cloos at jhcloos.com>         OpenPGP: 1024D/ED7DAEA6






More information about the cups mailing list