PHP讀取PDF頁數的方法

/**
    * 獲取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;
        }

  }

轉載自:http://www.9958.pw/post/php_pdf_totalpagephp

相關文章
相關標籤/搜索