Created
October 19, 2012 07:42
-
-
Save cloudsben/3916761 to your computer and use it in GitHub Desktop.
获取pdf总页数方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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