Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count pages in PDF file using Imagemagick - PHP

I am using PHP 5 with Apache 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.

I fount one solution here, but dont know how to open pdf file as text and count pages.

somebody give me a clear solution to count pages using imagemagick like

identify -format %n testfile.pdf

From googling, I found some workarounds or examples;

  1. imagick(identify -format %n testfile.pdf)
  2. identify -density 12 -format "%p" testfile.pdf
  3. identify -format %n testfile.pdf

I don't know how to make use of this stuff..

like image 484
Alfred Avatar asked Sep 18 '11 15:09

Alfred


2 Answers

Instead of using "identify -format %n $file"(which can turn out to be extremely slow for complex or for mult-page PDFs) you should rather use the right tool for the job, pdfinfo:

exec("pdfinfo $file | grep Pages: | awk '{print $2}'")

which is faster by several magnitudes...

like image 51
Kurt Pfeifle Avatar answered Oct 06 '22 12:10

Kurt Pfeifle


I solved it using;

exec("identify -format %n $file")

like image 32
Alfred Avatar answered Oct 06 '22 10:10

Alfred