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

Laravel Pdf Laravel Package

spatie/laravel-pdf

Create PDFs in Laravel apps from Blade views using Chromium (Browsershot, chrome-php), Gotenberg, Cloudflare Browser Run, WeasyPrint, or DOMPDF. Save to disk or return as a download, with full control over page format and modern CSS.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

spatie/laravel-pdf is a thin, opinionated facade over a pluggable rendering engine, not a PDF writer. That distinction matters architecturally: the package owns the Laravel-facing concerns (Blade view → HTML → PDF pipeline, storage/response handling, testing fakes, Blade directives) while delegating rasterization and pagination to a swappable driver. For a standard Laravel monolith or a modular monolith, it slots in with near-zero architectural friction: one composer dependency, one config file, one facade. No new datastore, no schema changes, no event bus.

The strategic value for a TPM is driver abstraction as a de-risking layer. Six drivers are supported with materially different operational profiles:

Driver Runtime dependency CSS fidelity Ops profile
Browsershot (Chromium) Node + Puppeteer + Chromium co-located with PHP Highest (grid, flex, web fonts) Heavy images, memory spikes on PHP hosts
Gotenberg Docker sidecar, HTTP API Highest Isolated, independently scalable — best for containers/K8s
Cloudflare Browser Run Fully managed, no infra Highest Data egress to a third party; per-request cost
WeasyPrint Python Strong CSS Paged Media, weaker flex/grid Lightweight, excellent page/header control
DOMPDF Pure PHP Limited (no grid/flex) Zero system deps; ideal for dev/CI/fallback
chrome-php/chrome Chromium via CDP High Similar to Browsershot, different client library

Because application code (Pdf::view(...)->format('a4')->save(...)) is driver-agnostic, we can commit to the package while deferring — or later reversing — the runtime decision. That is the single largest technical risk reducer here.

Integration feasibility

Low. The public surface is small and conventional: Blade views plus a builder with format(), name(), save() (disk-aware), download/streamed responses, and per-page header/footer directives. The changelog shows steady, incremental hardening of exactly the integration points we care about — disk handling normalized in 1.5.3, name/download semantics corrected in 1.5.0/1.5.1, spatie/browsershot v5 support added in 1.5.3, Laravel 12 compatibility in 1.5.5. That is a package being polished rather than one still searching for its API.

A genuine differentiator is the testing story: Pdf::fake() with assertRespondedWithPdf() / assertDontSee() lets PDF generation participate in the normal feature-test suite, and pdftotext-based content assertions are supported. Most PDF tooling in the PHP ecosystem has no first-class test double; this one does. It ships a Laravel Boost skill as well, which measurably reduces AI-assisted codegen errors.

Technical risk

  • Runtime dependency risk is the dominant risk, not code risk. Every high-fidelity driver requires a headless browser (or a Python/PDF toolchain) adjacent to PHP. That adds a new artifact to the build pipeline, a new CVE surface to patch, and new resource limits to tune.
  • Signal quality on adoption. The supplied metadata (dependents: 0, a 39/100 composite, a future-dated last release of 2026-10-05) is internally inconsistent with a 1k-star, actively maintained Spatie package at 1.5.x. I would treat the score as unreliable and verify adoption against Packagist download stats and our own reference checks before weighting it.
  • 1.x semantics. The API is stable in practice but semver permits breaking changes on minor bumps. Pin the version and review changelogs.
  • Known functional gaps: no native PDF/A, PDF/UA accessibility tagging, or digital signatures. If invoices must be archived compliantly or signed, plan for a downstream tool.
  • Third-party data egress if Cloudflare Browser Run is chosen — templates containing PII leave our perimeter.

Key questions

  1. Which driver, and does our production image already permit Node/Chromium, or must we add a Gotenberg sidecar?
  2. What is monthly PDF volume, and what is the p95 of concurrent renders? Rendering is seconds-scale and CPU-bound.
  3. Synchronous (user waits) or queued (user is emailed/notified)? This drives virtually every SLA decision.
  4. Do documents contain PII/PHI, and does that rule out managed rendering?
  5. Accessibility or archival compliance required (PDF/UA, PDF/A, e-signature)?
  6. Multi-language content — are the required glyph sets and RTL fonts available in the render container?

Integration Approach

Stack fit

Laravel 10–12 with PHP 8.x, Blade for templates, and existing filesystem disks for output. No new services required if DOMPDF is acceptable; one container if Gotenberg. The package reuses our existing view, storage, queue, and config conventions, so it does not introduce a parallel idiom that engineers must learn.

Migration path

Assume an existing barryvdh/laravel-dompdf, knp-snappy/wkhtmltopdf, or hand-rolled Browsershot implementation. Because the package renders Blade views, migration is mostly mechanical rather than a rewrite:

  1. Inventory existing PDF templates and classify by CSS complexity (simple tables vs. designed layouts).
  2. Map PDF::loadView(...)->setPaper(...)-style calls to Pdf::view(...)->format(...); keep views unchanged initially.
  3. Implement the package behind an internal DocumentRenderer interface so callers don't couple to the facade — this preserves the option to revert or dual-run.
  4. Run both paths in parallel for one release cycle on non-critical documents; diff output visually.

Compatibility

Existing disk abstraction and responses are respected; no conflict with queueing, Horizon, or Octane (though Octane plus co-located Puppeteer warrants a memory ceiling test). WeasyPrint and DOMPDF are additive, not exclusionary — we can ship DOMPDF in CI for speed and Gotenberg in production for fidelity, using driver configuration per environment. That environment-scoped driver strategy is worth adopting deliberately rather than discovering accidentally.

Sequencing

  1. Pilot (1–2 sprints): one low-blast-radius document (internal receipt or statement) on DOMPDF or Browsershot in a staging container. Prove CI, fonts, and page-break behavior.
  2. Runtime decision (same window): benchmark a representative document on Browsershot vs. Gotenberg for latency, memory, and image size. Decide once, record the rationale.
  3. Harden: queue-backed generation, timeout/retry policy, storage retention, observability.
  4. Migrate breadth: remaining templates one at a time, with the parallel-run gate.
  5. Decommission the legacy renderer and remove its system dependencies from the image.

Operational Impact

Maintenance

Package maintenance is light — Spatie ships regular point releases, mostly dependency bumps and small fixes, with clear changelogs. The real maintenance load is the render runtime: Chromium/Node or Gotenberg/Python image rebuilds, CVE patching, and font package updates. Budget for a recurring, if small, platform task, not a zero-cost dependency. Pin the composer constraint and review minor versions quarterly.

Support

Vendor risk is low: MIT license, well-known maintainer, documentation site, changelog discipline, active issue triage. No commercial SLA — support is community-based, so internal ownership must be explicit. Assign one engineer as the PDF domain owner; the knowledge is concentrated in CSS-for-print and container configuration, both of which are easy to lose.

Scaling

Rendering is CPU- and memory-bound and does not scale like typical PHP request handling. Two viable models:

  • Gotenberg sidecar: scales horizontally independent of the app tier, isolates crashes, keeps PHP workers lean. Preferred above roughly a few hundred documents per day or any bursty traffic.
  • Co-located Chromium: simplest to start, but couples PHP worker memory limits to render spikes and can starve the request pool. Only safe with conservative concurrency limits and a dedicated worker pool.

Default to asynchronous: enqueue generation, store to a disk, and notify or serve a signed URL. This keeps user-facing p95 latency independent of document complexity and gives free retry semantics.

Failure modes

  • Render timeout on large or image-heavy documents — needs explicit per-render timeouts and a bounded retry policy with dead-lettering.
  • OOM / Chromium crash under concurrency — cap worker concurrency below observed memory headroom; treat as a capacity signal.
  • Missing fonts or glyphs producing silent tofu boxes for non-Latin content — validate against the actual production image, not a dev machine.
  • CSS divergence between drivers — a template that looks correct on Browsershot may break on WeasyPrint. Lock the driver per environment and add visual checks.
  • Sandbox/security flags — headless Chromium in containers typically needs --no-sandbox, which weakens isolation. Gotenberg or a network-isolated sidecar mitigates this; document the decision.
  • Storage growth — PDFs are large; enforce retention and lifecycle rules on the output disk from day one.
  • External dependency outage if Cloudflare Browser Run is used — requires a fallback driver or graceful degradation.

Ramp-up

Very low for application developers: the builder API is discoverable in under an hour and the docs are focused. Realistic estimate is 1–2 days for a mid-level Laravel engineer to ship a production-quality template, with the majority of that time spent on print CSS (page breaks, running headers, margins) rather than the package. Platform effort is higher and front-loaded — roughly 2–4 days to containerize and validate the render runtime, plus CI wiring for pdftotext/Puppeteer so the test fakes and content assertions run in the pipeline. The bundled Laravel Boost skill further lowers the cost of correct first-attempt code from AI tooling.

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.
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode