composer require smalot/pdfparser
1.一次性读取文件中的所有内容:
parseFile('ces.pdf'); //直接读取文件//方法二$content = file_get_contents('ces.pdf');$pdf = $parser->parseContent($content); //文件流$text = $pdf->getText();echo $text;
2.分页读取:
include 'vendor/autoload.php';$parser = new \Smalot\PdfParser\Parser();$pdf = $parser->parseFile('document.pdf');$pages = $pdf->getPages(); //分页信息foreach ($pages as $page) { echo $page->getText(); //输出每一页的内容}
3.获取文件的基本信息,如:制作人、日期、总页数等
include 'vendor/autoload.php';$parser = new \Smalot\PdfParser\Parser();$pdf = $parser->parseFile('document.pdf');$details = $pdf->getDetails();
来源地址:https://blog.csdn.net/qq_36345633/article/details/130384742