spatie / laravel-pdf
Create PDFs in Laravel apps
Installs: 547 389
Dependents: 4
Suggesters: 0
Security: 0
Stars: 715
Watchers: 11
Forks: 54
Open Issues: 9
Requires
- php: ^8.2
- illuminate/contracts: ^10.0|^11.0
- spatie/browsershot: ^4.0
- spatie/laravel-package-tools: ^1.16.1
- spatie/temporary-directory: ^2.2.1
Requires (Dev)
- ext-imagick: *
- larastan/larastan: ^2.7.0
- laravel/pint: ^1.13.7
- nunomaduro/collision: ^7.10
- orchestra/testbench: ^8.18
- pestphp/pest: ^2.30
- pestphp/pest-plugin-arch: ^2.5
- pestphp/pest-plugin-laravel: ^2.2
- phpstan/extension-installer: ^1.3.1
- phpstan/phpstan-deprecation-rules: ^1.1.4
- phpstan/phpstan-phpunit: ^1.3.15
- spatie/image: ^3.3.2
- spatie/laravel-ray: ^1.33
- spatie/pdf-to-image: ^2.2
- spatie/pdf-to-text: ^1.52.1
- spatie/pest-expectations: ^1.5
- spatie/pest-plugin-snapshots: ^2.1
- spatie/pixelmatch-php: ^1.0
- wnx/sidecar-browsershot: ^2.0
README
This package provides a simple way to create PDFs in Laravel apps. Under the hood it uses Chromium to generate PDFs from Blade views. You can use modern CSS features like grid and flexbox to create beautiful PDFs.
Here's a quick example:
use Spatie\LaravelPdf\Facades\Pdf; Pdf::view('pdfs.invoice', ['invoice' => $invoice]) ->format('a4') ->save('invoice.pdf')
This will render the Blade view pdfs.invoice
with the given data and save it as a PDF file.
You can also return the PDF as a response from your controller:
use Spatie\LaravelPdf\Facades\Pdf; class DownloadInvoiceController { public function __invoke(Invoice $invoice) { return Pdf::view('pdfs.invoice', ['invoice' => $invoice]) ->format('a4') ->name('your-invoice.pdf'); } }
You can use also test your PDFs:
use Spatie\LaravelPdf\Facades\Pdf; it('can render an invoice', function () { Pdf::fake(); $invoice = Invoice::factory()->create(); $this->get(route('download-invoice', $invoice)) ->assertOk(); Pdf::assertRespondedWithPdf(function (PdfBuilder $pdf) { return $pdf->contains('test'); }); });
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Documentation
All documentation is available on our documentation site.
Testing
For running the testsuite, you'll need to have Puppeteer installed. Pleaser refer to the Browsershot requirements here. Usually npm -g i puppeteer
will do the trick.
Additionally, you'll need the pdftotext
CLI which is part of the poppler-utils package. More info can be found in in the spatie/pdf-to-text readme. Usually brew install poppler-utils
will suffice.
Finally run the tests with:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.