spatie-pdf-to-imagePDF 轉(zhuǎn)圖像工具
spatie-pdf-to-image 提供了一個(gè)易于使用的類來將 PDF 轉(zhuǎn)換為圖像。
要求
需安裝 Imagick 和 Ghostscript
安裝
該軟件包可以通過 composer 安裝:
composer require spatie/pdf-to-image
用法
將 pdf 轉(zhuǎn)換為圖像很容易。
$pdf = new Spatie\PdfToImage\Pdf($pathToPdf); $pdf->saveImage($pathToWhereImageShouldBeStored);
如果傳遞給saveImage的路徑有擴(kuò)展jpg,jpeg或png,圖像像將被保存為該格式。否則輸出將是 jpg。
其他方法
可以獲得 PDF 中的總頁數(shù):
$pdf->getNumberOfPages(); //returns an int
默認(rèn)情況下,將呈現(xiàn) PDF 的第一頁。如果想渲染另一個(gè)頁面,你可以這樣做:
$pdf->setPage(2) ->saveImage($pathToWhereImageShouldBeStored); //saves the second page
可以覆蓋輸出格式:
$pdf->setOutputFormat('png') ->saveImage($pathToWhereImageShouldBeStored); //the output wil be a png, no matter what
可以將壓縮質(zhì)量設(shè)置為 0 到 100:
$pdf->setCompressionQuality(100); // sets the compression quality to maximum
評(píng)論
圖片
表情
