Weave Code
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 Pdf Laravel Package

spatie/laravel-pdf

Generate PDFs from Laravel Blade views with a simple fluent API. Choose drivers like Browsershot/Chromium, Gotenberg, Cloudflare Browser Run, WeasyPrint, DOMPDF, or chrome-php. Use modern CSS, set page formats, and stream or save PDFs.

View on GitHub
Deep Wiki
Context7

Create PDFs in Laravel apps

Frequently asked questions about Laravel Pdf
How do I install spatie/laravel-pdf in a Laravel project?
Run `composer require spatie/laravel-pdf` in your project directory. The package auto-discovers Laravel and no additional configuration is needed for basic usage. For specific drivers like Browsershot or Gotenberg, follow their individual setup guides.
Which PDF driver should I choose for modern CSS support?
Use **Browsershot** or **Cloudflare Browser Rendering** for full modern CSS support (Flexbox, Grid). These Chromium-based drivers render HTML like a real browser. For simpler layouts, **DOMPDF** works but lacks advanced CSS features.
Can I generate PDFs asynchronously in Laravel queues?
Yes, dispatch a job to generate the PDF and return it later. Use `Pdf::view()->save()` in the job’s `handle()` method. For Chromium-based drivers, ensure the worker has access to required dependencies (e.g., Docker for Gotenberg).
Does spatie/laravel-pdf support Laravel 10 or 11?
The package is fully compatible with Laravel 10 and 11. It leverages Laravel’s service container and facades, so no version-specific changes are required. Always check the [GitHub releases](https://github.com/spatie/laravel-pdf/releases) for updates.
How do I test PDF generation in Laravel’s testing environment?
Use `Pdf::fake()` to mock PDF generation in tests. Assert the view was rendered with `Pdf::assertSaved()` or `Pdf::assertDownloaded()`. For complex layouts, manually verify the output by saving the PDF and comparing it to a reference file.
What are the memory/performance implications of Chromium-based drivers?
Chromium drivers (Browsershot, Chrome-PHP) consume significant memory and CPU, especially for large or complex PDFs. For production, use queues or async processing. If scaling is critical, consider **Gotenberg** (Docker) with a dedicated service or **Cloudflare Browser Rendering** for offloaded processing.
Is there a fallback driver if my primary one fails?
The package doesn’t enforce a fallback by default, but you can implement logic in your controller to catch exceptions (e.g., `try-catch`) and switch to a secondary driver like DOMPDF. Example: `try { Pdf::view()->save(); } catch (...) { Pdf::setDriver('dompdf')->save(); }`
How do I add headers/footers or custom metadata to PDFs?
Use the fluent API methods: `Pdf::view()->setOptions(['title' => 'Invoice', 'subject' => 'Payment'])`, or add headers/footers via Blade templates (e.g., `@include('pdfs.header')`). For driver-specific options like page margins, consult the [documentation](https://spatie.be/docs/laravel-pdf).
Can I use this package outside Laravel (e.g., plain PHP or Symfony)?
The package is Laravel-specific and relies on its service container and Blade integration. For non-Laravel use, manually bind the PDF service or adapt the logic to your framework’s DI container. Consider alternatives like **DOMPDF** or **SnappyPDF** for broader compatibility.
Are there security risks with user-provided HTML/CSS in PDF templates?
Yes, user-provided HTML/CSS can lead to CSS injection or malicious payloads. Sanitize inputs using Laravel’s `Str::of()` or libraries like **HTML Purifier**. Avoid dynamic CSS from untrusted sources, especially with Chromium drivers that execute JavaScript.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai