Skip to content

Instantly share code, notes, and snippets.

@jgdoncel
Created May 8, 2012 09:06
Show Gist options
  • Save jgdoncel/f72176ceb58d3553dd7b to your computer and use it in GitHub Desktop.
Save jgdoncel/f72176ceb58d3553dd7b to your computer and use it in GitHub Desktop.
Contar páginas de un PDF
function getNumPagesInPDF($file)
{
//http://www.hotscripts.com/forums/php/23533-how-now-get-number-pages-one-document-pdf.html
if(!file_exists($file))return null;
if (!$fp = @fopen($file,"r"))return null;
$max=0;
while(!feof($fp)) {
$line = fgets($fp,255);
if (preg_match('/\/Count [0-9]+/', $line, $matches)){
preg_match('/[0-9]+/',$matches[0], $matches2);
if ($max<$matches2[0]) $max=$matches2[0];
}
}
fclose($fp);
return (int)$max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment