You are here

function pdf_to_image_count_pages in PDF to ImageField 7.2

Same name and namespace in other branches
  1. 7.3 pdf_to_image.module \pdf_to_image_count_pages()

Use imagemagick routine to count the number of pages in a given PDF

1 call to pdf_to_image_count_pages()
pdf_to_image_generate_process in ./pdf_to_image.module
Processing pdf file creation.

File

./pdf_to_image.module, line 583
Implement a pdf field, based on the file module's file field.

Code

function pdf_to_image_count_pages($filepath) {
  $convert_path = variable_get('imagemagick_convert', '/usr/bin/convert');
  $identify_path = dirname($convert_path) . '/identify';

  // Identify renders every page in the pdf to count the number of pages which
  // can be a problem (server timeout) when processing a pdf with many pages.
  // The better command commented because it working very slow.
  // "{$identify_path} -format %n " . escapeshellarg($fpath) . ' 2> /dev/null';
  $command = "{$identify_path} " . escapeshellarg($filepath) . '[9999] | grep "Requested FirstPage" | cut -d : -f2';
  $count = shell_exec($command);
  return (int) $count;
}