内容 |
本文实例讲述了PHP简单读取PDF页数的实现方法。分享给大家供大家参考,具体如下: 还是老外比较厚道, 在老外的网站找到了这样一个方法,我写成了一个函数, 再将函数写进自己的LeeLib库里的PdfUtil类. 很简单的方式, 速度还不错. /** * 获取PDF的页数 */ function getPageTotal($path){ // 打开文件 if (!$fp = @fopen($path,"r")) { $error = "打开文件{$path}失败"; return false; } else { $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 $max; } } 希望本文所述对大家PHP程序设计有所帮助。
|