http://www.perlmonks.org?node_id=812398


in reply to Get PDF page count

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’,);