views:

23

answers:

1

Hi Could someone suggest the php code using exec() function to execute a binary of imagick to count the pages in a pdf file. Any suggestions would be great. Thanks!

Regards Rahul

A: 

Please keep in mind that ImageMagick uses ghostscript to slurp pdf files, so this may be a grossly inefficient way to simply count pages.

What I do is use pdftk to burst the pages, then count the number of output files. But it happens that I also want to process the output files.

You can also use pdftk's data dump to count the pages.

This command line works nicely on *nix.

pdftk myfile.pdf dump_data | grep NumberOfPages | cut -d " " -f 2
Ollie Jones