1:Imagick拓展
2:php的spatie/pdf-to-image插件包
3:Ghostscript软件
composer require spatie/pdf-to-image
tar -xzf ghostscript-9.56.1.tar.gz
cd ghostscript-9.56.1
./configure
make && make install
修改/etc/ImageMagick-6/policy.xml文件
(1):将pattern="{PS,PDF,XPS}"这行修改成
<policy domain="module" rights="read|write" pattern="{PS,PDF,XPS}" />
(2):将pattern="PDF"修改成
<policy domain="coder" rights="read|write" pattern="PDF" />
$pdfPath = 'XXX';//PDF地址
$pdfToImg = new \Spatie\PdfToImage\Pdf($pdfPath);
$pages = $pdfToImg->getNumberOfPages();
$fullPath = 'XXX';//图片保存地址
$imgs = [];
for ($i = 1; $i <= $pages; $i++) {
$imgFile =$i . '.png';
$pdfToImg->setPage($i)->saveImage($fullPath . '/' . $imgFile);
$imgFiles[] = $fullPath . $imgFile;
}
return $imgFiles;//图片地址数组
根据如上就可以实现将pdf转成图片,多张pdf会转成多张图片