Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Get PDF page count

by rose (Beadle)
on Dec 11, 2009 at 14:20 UTC ( #812381=perlquestion: print w/replies, xml ) Need Help??
rose has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I need to get page count for given PDF file name. So, I used PDF module as follows:

print "This file has ",$pdf->Pages," Pages \n";

Is there any other getting the page count like this?

Thanks
Rose

Replies are listed 'Best First'.
Re: Get PDF page count
by marto (Bishop) on Dec 11, 2009 at 14:26 UTC

    CAM::PDF has a numPages() method.

    Martin

Re: Get PDF page count
by leocharre (Priest) on Dec 11, 2009 at 16:06 UTC
    sub pdf_pagecount { scalar @_ or confess('missing arg'); my $count=0; require PDF::API2; require Carp; PDFILE : while( my $abs = shift @_){ -f $abs or Carp::cluck("!-f $abs") and return 0; my $p = PDF::API2->open($abs) or die; my $_count; unless( $_count = $p->pages ){ Carp::cluck("doc $abs had no pagecount?"); next PDFILE; } $count= ($count + $_count); } return $count; }

    Arg is abs path to pdf tests for existance returns count of pages. Arg can be list, checks each and warns and returns false on errors.

    my $pagecount= pdf_pagecount(’/my/abs/file.pdf’); my $total_pagecount= pdf_pagecount( '/my/abs/file.pdf’, ’/my/abs/file +2.pdf’,);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://812381]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2016-09-25 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (474 votes). Check out past polls.