PHP读取PDF页数的方法

1580阅读 0评论2016-07-07 rin9958
分类:Web开发

/**
    * 获取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 curl post 上传文件流
下一篇:LINUX启动/重启/停上MYSQL的命令