Count number of pages in PDF file

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
blasteralfred
Posts: 1
Joined: 2011-09-19T00:37:24-07:00
Authentication code: 8675308

Count number of pages in PDF file

Post by blasteralfred »

Hi,

I am using PHP 5 with Apache 2 in my Windows Vista PC. I have Imagemagick already installed and configured. I want to count the total number of pages in a pdf file using imagick.

Can somebody give me a clear and complete solution to count pages using imagemagick? (i am a beginner)

From googling, I found some examples;

Code: Select all

imagick(identify -format %n testfile.pdf) 

Code: Select all

identify -density 12 -format "%p" testfile.pdf 

Code: Select all

identify -format %n testfile.pdf 
I don't know how to make use of this stuff..

Thanks in advance... :)

blasteralfred
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Count number of pages in PDF file

Post by Bonzo »

Not sure how it works with Imagick but this will work for Imagemagick and the command line:

Code: Select all

$pages = exec("identify -format %n testfile.pdf");

echo $pages;
You could see if you can work out how to use imagick to do the above with the info here: http://uk3.php.net/imagick
Post Reply