Spatie Laravel PDF is a package designed to simplify PDF creation within Laravel applications. Created by Spatie, a web development company known for its open-source Laravel packages, it offers a fluent interface for generating PDFs from HTML, Blade templates, or raw strings. The package is versatile, supporting multiple drivers for PDF generation, including Browsershot (Chromium via Puppeteer), Cloudflare Browser Rendering API, DomPdf (pure PHP), and Gotenberg (Docker-based). This allows developers to select the most suitable backend based on their specific needs and infrastructure.
Key features of Laravel PDF include queued PDF generation, support for PDF metadata (title, author, keywords), runtime driver switching, and custom driver support. Version 2 introduced a driver-based architecture for greater flexibility. The package also facilitates the use of modern CSS features like grid and flexbox (with Chromium-based drivers) and offers methods for formatting PDFs, such as adding page numbers and changing page orientation. As an open-source package, Laravel PDF is freely available. However, using certain drivers like Cloudflare's Browser Rendering API may incur costs depending on usage. To use the package, it can be installed via composer using the command composer require spatie/laravel-pdf.