Count The Number of Pages in a PDF


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. METHOD 1
  2. ImageMagick: identify -density 12 -format "%p" image.pdf
  3.  
  4. METHOD 2
  5. FPDI (when setting the source file you get back the page count):
  6. http://www.setasign.de/products/pdf-php-solutions/fpdi/demos/thumbnails/
  7.  
  8. METHOD 3
  9. Open the pdf as a text file and count the number of times "/Page" occurs.
  10. function count_pages($pdfname) {
  11. $pdftext = file_get_contents($pdfname);
  12. $num = preg_match_all("/\/Page\W/", $pdftext, $dummy);
  13. return $num;
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.