Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Laravel Pdf

spatie/laravel-pdf image

Laravel Pdf stats

Downloads
154
Stars
283
Open Issues
0
Forks
9

View on GitHub →

Create PDFs in Laravel apps

Spatie Laravel PDF

The Spatie Laravel PDF package enables easy PDF generation in Laravel applications, leveraging Chromium to convert Blade views into PDF files. This approach allows developers to utilize advanced CSS features like Flexbox and Grid in their PDF designs.

Key Features

  • Generate PDFs from Blade Views: Render any Blade view as a PDF file, passing necessary data directly into the view.
  • Modern CSS Support: Design your PDF layouts using modern CSS, thanks to the underlying use of Chromium.
  • Save or Stream PDFs: Easily save generated PDFs to the server or stream them directly to the user for downloads.
  • Testing Support: Includes functionality to fake PDF downloads in tests to ensure your application behaves as expected without generating actual files during testing.

Installation and Usage

To install the package, run:

composer require spatie/laravel-pdf

Basic Usage

Generate a PDF by rendering a Blade view:

use Spatie\LaravelPdf\Facades\Pdf;
 
Pdf::view('pdfs.invoice', ['invoice' => $invoice])
->format('a4')
->save('invoice.pdf');

To send a PDF as a downloadable response:

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');
}
}

Testing

Ensure Puppeteer is installed (npm -g i puppeteer) and pdftotext from poppler-utils (brew install poppler-utils), then run:

composer test

Documentation and Support

Full documentation is available on the Spatie documentation site. For more extensive support and contributions, visit the GitHub repository or the Spatie website.

Contributions and Security

Contributions are welcome! Please see the repository's CONTRIBUTING guide for more details. For security issues, refer to the project's security policy.


This package is part of Spatie's suite of open-source tools. Support their work by purchasing a product or sending a postcard.

spatie photo

We create open source, digital products and courses for the developer community

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Spatie Laravel Pdf Related Articles

Lens for Laravel Brings WCAG Auditing to Your Local Dev Workflow image

Lens for Laravel Brings WCAG Auditing to Your Local Dev Workflow

Read article
Generate PDFs in Laravel from Blade Views image

Generate PDFs in Laravel from Blade Views

Read article
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu