本文實(shí)例講述了PHP簡單讀取PDF頁數(shù)的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
還是老外比較厚道, 在老外的網(wǎng)站找到了這樣一個方法,
我寫成了一個函數(shù), 再將函數(shù)寫進(jìn)自己的LeeLib庫里的PdfUtil類.
很簡單的方式, 速度還不錯.
/** * 獲取PDF的頁數(shù) */ 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); // 返回頁數(shù) return $max; } }} |