PHP 读取 pdf 文件

官网地址:smalot/pdfparser

一次性读取文件中的所有内容

$parser = new \Smalot\PdfParser\Parser();// 引用类,具体根据自己文件位置
$pdf = $parser->parseFile($file_path_name); // 根目录下的文件路径
echo $pdf->getText(); //将所有内容读取到一个字符串中

分页读取

$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile($file_path_name);  // 根目录下的文件路径
$pages = $pdf->getPages(); //分页信息
foreach ($pages as $page) {
    echo $page->getText(); //输出每一页的内容
}

获取文件的基本信息,如:制作人、日期、总页数

$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile($file_path_name); // 根目录下的文件路径
$details = $pdf->getDetails();
parint_r($details);

 

posted @   柔和的天空  阅读(2466)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示