Skip to content

Instantly share code, notes, and snippets.

@cloudsben
Created October 19, 2012 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudsben/3916761 to your computer and use it in GitHub Desktop.
Save cloudsben/3916761 to your computer and use it in GitHub Desktop.
获取pdf总页数方法
function getNumPagesInPDF($PDFPath)
{
$stream = @fopen($PDFPath, "r");
$PDFContent = @fread ($stream, filesize($PDFPath));
if(!$stream || !$PDFContent)
return false;
$firstValue = 0;
$secondValue = 0;
if(preg_match("/\/N\s+([0-9]+)/", $PDFContent, $matches)) {
$firstValue = $matches[1];
}
if(preg_match_all("/\/Count\s+([0-9]+)/s", $PDFContent, $matches))
{
$secondValue = max($matches[1]);
}
echo (($secondValue != 0) ? $secondValue : max($firstValue, $secondValue));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment