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 Dompdf

Laravel Dompdf Laravel Package

barryvdh/laravel-dompdf

Laravel wrapper for Dompdf to generate PDFs from HTML views. Provides a PDF facade/service, easy rendering, streaming or downloading responses, and simple configuration—ideal for invoices, reports, and other printable documents in Laravel apps.

View on GitHub
Deep Wiki
Context7

barryvdh/laravel-dompdf integrates the Dompdf HTML-to-PDF engine into Laravel, making it simple to render PDFs from Blade views or raw HTML. It provides a familiar, Laravel-friendly API for generating, streaming, or downloading PDF responses with minimal setup.

Ideal for invoices, reports, and printable documents, the package wraps Dompdf configuration and rendering while fitting naturally into Laravel’s service container and response workflow.

  • Generate PDFs from Blade views or HTML strings
  • Stream inline or download as an attachment
  • Configure paper size, orientation, margins, and options
  • Embed images/fonts and handle CSS (within Dompdf limits)
  • Laravel-friendly facade and service provider integration
Frequently asked questions about Laravel Dompdf
How do I install and set up barryvdh/laravel-dompdf in a Laravel project?
Run `composer require barryvdh/laravel-dompdf` to install. The package auto-discovers Laravel and publishes a config file (`config/dompdf.php`) for customization. No additional setup is needed for basic usage, but you can publish the config with `php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"` for manual adjustments.
What Laravel versions does barryvdh/laravel-dompdf support?
The package supports Laravel 11, 12, and 13 (as of v3.1.2). Older versions (e.g., Laravel 10) may work but are not officially tested. Always check the [GitHub releases](https://github.com/barryvdh/laravel-dompdf/releases) for compatibility notes before upgrading.
Can I generate PDFs from Blade views or raw HTML strings?
Yes. Use `Pdf::loadView('view.name')` for Blade templates or `Pdf::loadHTML($htmlString)` for raw HTML. Both methods integrate seamlessly with Laravel’s routing and response system. For example, return `Pdf::loadView('invoice')->stream('invoice.pdf')` in a controller to stream the PDF.
How do I configure default PDF settings like paper size or margins?
Edit the `config/dompdf.php` file to set defaults like `default_paper_size`, `default_orientation`, or `default_font`. You can also override settings per request using methods like `Pdf::setPaper('A4', 'landscape')` or `Pdf::setOption('isHtml5ParserEnabled', true)`.
What are the differences between `stream()`, `download()`, and `save()` methods?
`stream()` sends the PDF inline (e.g., for preview), `download()` forces a download with a filename, and `save()` writes the PDF to disk (e.g., `Pdf::save(storage_path('reports/report.pdf'))`). Use `stream()` for real-time previews and `download()` for user-triggered exports.
Does barryvdh/laravel-dompdf support async PDF generation with Laravel queues?
Yes. Chain the `queue()` method to defer PDF generation: `Pdf::loadView('report')->queue(function ($job, $pdf) { $job->load($pdf->download('report.pdf')); })`. This is useful for long-running or resource-intensive PDFs to avoid timeouts or blocking the user.
How do I handle custom fonts or images in PDFs?
Custom fonts require manual installation in Dompdf’s font directory (e.g., `vendor/dompdf/dompdf/lib/fonts/`). Use `Pdf::setOption('font_dir', storage_path('fonts'))` to specify a custom path. For images, ensure they’re accessible via a URL or local path, and Dompdf will embed them automatically.
What are the security implications of using dompdf v3.x with Laravel?
Dompdf v3.x disables remote content by default (`enable_remote = false`). If your app uses external resources (e.g., images from a CDN), whitelist allowed hosts in `config/dompdf.php` under `allowedRemoteHosts`. Protocol validation (e.g., blocking `data://` URIs) may also require config updates if you rely on inline data.
How can I test PDF generation in Laravel’s testing environment?
Use Laravel’s `Pdf::fake()` helper to mock PDF generation in tests. For example: `Pdf::fake(); $response = $this->get('/invoice'); Pdf::assertDownloaded('invoice.pdf')`. This prevents actual PDF generation during tests and verifies the correct file is triggered.
What alternatives exist for HTML-to-PDF in Laravel, and when should I consider them?
Alternatives include `spatie/laravel-pdf` (wrapper for SnappyPDF/WKHTMLtoPDF), `mikehaertl/phpwkhtmltopdf` (direct WKHTMLtoPDF), or `barryvdh/laravel-snappy` (SnappyPDF). Choose WKHTMLtoPDF-based solutions for complex CSS/JS rendering or if you need Chrome-headless support. Use Dompdf for simpler, server-dependent PDFs with minimal dependencies.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport