MerchantryTidbits

document-automation / library

spatie/pdf-to-image

Capability: spatie/pdf-to-image

Use it when

  • A PHP or Laravel app must show image previews or thumbnails of uploaded PDF pages without a client-side PDF viewer
  • Every page of a PDF needs to be exported as jpg, png, or webp at a controlled DPI, size, and quality for downstream processing

What it solves

Not the fit when

  • Extracting text, tables, or structure from PDFs
  • Environments where Imagick and Ghostscript cannot be installed
  • Password-protected PDFs on ImageMagick 6, where `password()` raises `PasswordNotSupported`
  • Blindly weakening ImageMagick's PDF security policy; any policy.xml change should be narrowly scoped and reviewed against the deployment's untrusted-file threat model
  • text or table extraction from pdfs
  • pdf generation or editing
  • filling pdf forms
  • ocr of scanned pages

Install

composer require spatie/pdf-to-image (requires PHP 8.2+, Imagick, and Ghostscript)

Invoke

$pdf = new \Spatie\PdfToImage\Pdf($pathToPdf); $pdf->save($path); chain selectPage()/selectPages(), format(), resolution(), quality(), thumbnailSize(), or saveAllPages($dir); password() handles encrypted PDFs on ImageMagick 7

Alternatives

No reviewed alternatives recorded yet.