早睡早起,方能养生
Sleep early rise early, way to keep healthy

PHP PDF转PNG图片

super
2023-01-09 21:39
views 101

1)安装 PHP Imagick 拓展

 

2)安装 ghostscript

 

https://rongsp.com/article/310.html

 

3)安装spatie/pdf-to-image

 

composer require spatie/pdf-to-image

 

 

4)转换

 

$pathToPdf = './test.pdf';

$pdf = new \Spatie\PdfToImage\Pdf($pathToPdf);
$total = $pdf->getNumberOfPages();

for ($i = 1; $i <= $total; $i++ ) {
	$pdf->setOutputFormat('png')
		->setPage($i)
		->saveImage('./' . $i . '.png');
}

 



分享
0 条讨论
top