Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pdf To Image Laravel Package

spatie/pdf-to-image

Convert PDF pages to images with this simple PHP class built on Imagick and Ghostscript. Save as jpg, jpeg, png, or webp, render any page, and check page counts. Requires PHP 8.2+.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

Feature bets this unblocks (fast, cheap):

  • Document previews and thumbnails — first-page previews for invoice, contract, statement, and report libraries; a 400px thumbnailSize() thumbnail is one call. This is the single highest-leverage use case and typically a "table stakes" gap in B2B document products.
  • Multi-page document viewers — selectPage() / selectPages() / saveAllPages() lets you build a page-strip or carousel rather than a single cover image.
  • Visual QA and proofing workflows — render at resolution(300) to produce print-proof or pre-flight previews for a "this is what will be printed/mailed" confirmation step.
  • Downstream image pipelines — feeding thumbnails into OCR, classification, redaction-preview, or watermarking steps where the model/process expects a raster image, not a PDF.
  • Format and payload decisions — format(OutputFormat::Webp) plus quality() makes "store WebP derivatives, serve JPEG fallback" a one-line config choice rather than a research spike.

Build vs. buy: This is a buy decision that is really an infrastructure decision. The code is ~free (MIT, mature, Spatie-maintained); your actual investment is Ghostscript + ImageMagick on your PHP hosts and the operational work of running them safely. Framing it as "we write a wrapper class" is wrong — the wrapper is trivial, the binary dependency is not. Decide both together.

Roadmap sequencing: Because it is a small, boring, low-lock-in dependency (a single class, no service provider, no database), it is a good candidate for a spike-to-ship in one sprint for the preview feature. Don't let it sit on a roadmap as a "document rendering platform" initiative; that framing invites scope creep toward text extraction, editing, and annotation — none of which this package does.

Derivative storage strategy: save() returns a path (or array of paths for multi-page), so you must decide product-side: generate derivatives on upload (predictable, storage cost, instant previews) vs. on demand (cheaper storage, latency, needs caching). This package supports either; the decision is yours and it's a real cost/latency trade-off, not a technicality.

What this explicitly does not decide: searchable text, OCR, PDF generation/merge/split, redaction, annotation, form filling, digital signatures. If a stakeholder request contains those words, this package is one ingredient at most.

When to Consider This Package

Adopt when most of these hold:

  • PHP 8.2+ (v3+; v2.0 is the fallback for older runtimes) and you are on Laravel/PHP already.
  • You can install and pin Ghostscript + ImageMagick on your app/worker hosts, and you control policy.xml and php-fpm.conf (the README's two gotchas — FailedToExecuteCommand 'gs' under FPM and the security policy 'PDF' coder restriction — will otherwise burn a day of engineering).
  • Volume is low-to-moderate and queue-friendly; conversion is CPU/memory-heavy, so plan for async jobs with timeouts, not synchronous request-path rendering.
  • Input PDFs are first-party or trusted (documents you generated, or uploads from authenticated business customers).
  • You need exactly what it does: rasterize pages with control over DPI, quality, dimensions, background color, watermark-layer behavior, and output format.
  • Encrypted PDFs matter — note password() only works on ImageMagick 7 and throws PasswordNotSupported on IM6; verify with Pdf::supportsPasswordProtectedPdfs() before promising this to customers.

Look elsewhere when:

  • You can't own system binaries — serverless/container-restricted environments, or platform teams that won't approve Ghostscript. A hosted rendering API removes the ops burden at the cost of per-page pricing and an upload path for sensitive documents.
  • User-supplied PDFs from untrusted sources at scale. Ghostscript has a meaningful CVE history and this library is a thin wrapper over it — sandboxing, resource caps (policy.xml width/height limits), and file-size/type validation are your responsibility, not the package's. If you can't staff that, use a managed rendering service or an isolated worker.
  • Rendering fidelity is a product promise. If legal/finance require byte-faithful, font-perfect rendering of arbitrary third-party PDFs, headless Chrome/Gotenberg or a PDF.js-based viewer is a safer bet than Ghostscript rasterization.
  • You need text, not pixels — this yields images only. Text extraction (poppler/pdftotext) or OCR is a separate dependency; don't let anyone assume "PDF to image" gives you search.
  • You're redistributing an appliance/on-prem bundle. Ghostscript is AGPL in its default distribution; a managed SaaS deployment is generally fine, but shipping an on-prem binary bundle may require a commercial Ghostscript license or AGPL compliance review. Escalate to legal before the enterprise deal, not after.
  • Ultra-wide or large-format PDFs are core — the README's policy.xml width/height workaround signals real failure modes; validate against your actual document corpus first.
  • You want vector output (SVG) or streaming previews in the browser — different tooling.

Signal-quality caveat for the decision log: 1,460 stars and a Spatie-authored, MIT-licensed package with a changelog and recent releases indicate mature and low maintenance risk. The "0 dependents" figure is not a credible adoption signal (Packagist dependent counts are notoriously incomplete) — do not cite it as evidence of low usage in a build-vs-buy memo.

How to Pitch It (Stakeholders)

For executives (one paragraph): We can close a visible product gap — document thumbnails and page previews — with a mature, MIT-licensed open-source library instead of a paid rendering service or a custom build. The library itself is small and low-risk, maintained by Spatie, and requires no new vendor contract. The real commitment is modest but not zero: our servers must run Ghostscript and ImageMagick, which means a small amount of infrastructure hardening and a security review for how we handle customer-uploaded PDFs. Expect roughly one sprint to ship previews on trusted documents; untrusted uploads at scale should get a sandboxing review or a managed service, and any on-prem/enterprise distribution needs a licensing check because Ghostscript is AGPL. Recommendation: approve for the preview/thumbnail feature now, scoped to authenticated business documents, on background workers.

For engineering (the short version): spatie/pdf-to-image v3, PHP 8.2+, MIT. Plain class, no Laravel provider, trivial API (new Pdf($path)->selectPages(1,2)->thumbnailSize(400)->save($dir)). It does not generate, split, merge, extract text, redact, or annotate PDFs — rasterization only. Hard dependencies are Ghostscript + ImageMagick, which is where all the risk lives:

  • Pin and patch both binaries; treat Ghostscript CVEs as our problem.
  • Configure policy.xml (PDF coder read/write; width/height limits for ultra-wide docs) and php-fpm.conf env[PATH] so FPM can find gs.
  • Run conversions in queued jobs with timeouts and memory ceilings — never in the request path.
  • Validate uploads (size, MIME, page count via pageCount()) and cap pages rendered per document.
  • Encrypted PDFs work only on ImageMagick 7; gate the feature with Pdf::supportsPasswordProtectedPdfs().
  • Store derivatives (WebP/JPEG) rather than re-rendering per request; decide on-upload vs on-demand explicitly.
  • Ghostscript is AGPL — flag any plan to ship an on-prem bundle to legal early.

Ask: approve the dependency and the Ghostscript/ImageMagick host requirement for the preview epic; treat document-rendering hardening as a named work item, not incidental plumbing.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tagixo/document-builder
tagixo/page-builder
tagixo/mail-builder
tagixo/form-builder
primix/primix
tagixo/core
alesima/laravel-azure-service-bus
tomshaw/shopcart
likyly/laravel
darthsoup/shoppingcart
tdt/core
labyrinthe/connect-php
encore2/laravel-admin2
cboxdk/laravel-console-kit
shapecode/doctrine-dbal-datetimeutc
gilads-otiannoh254/inertia-protocol
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook