关于读取pdf文件信息

最近项目有个读取pdf页码的需求,试过老多方法,最终:

function get_pages($document){
            $cmd = "/usr/bin/pdfinfo";           // Linux
            // $document 这是文件路径
            exec("$cmd \"$document\"", $output);
            $pagecount = 0;
            foreach($output as $op)
            {
                // Extract the number
                if(preg_match("/Pages:\s*(\d+)/i", $op, $matches) === 1)
                {
                    $pagecount = intval($matches[1]);
                    break;
                }
            }
            return array(true,$pagecount);
            
        }

这是安装 pdfinfo的方法:  

yum install poppler-utils

posted @ 2021-09-13 17:22  wfc139  阅读(88)  评论(0编辑  收藏  举报