- Which Laravel versions does spatie/laravel-pdf support?
- The package officially supports Laravel 8+, 9, and 10. It follows Laravel’s release cycle and is regularly updated for compatibility. Always check the [GitHub repo](https://github.com/spatie/laravel-pdf) for the latest version’s supported range before upgrading.
- How do I install and configure spatie/laravel-pdf for basic PDF generation?
- Install via Composer with `composer require spatie/laravel-pdf`. No additional configuration is needed for basic use—just inject the `Pdf` facade into your controller or service. Example: `Pdf::view('pdfs.invoice', ['data' => $data])->download('invoice.pdf');`. The package auto-detects installed engines like DomPDF or Snappy.
- Can I use Blade templates to generate PDFs with this package?
- Yes, the package integrates seamlessly with Laravel Blade. Use `Pdf::view('view.name', $data)` to render a Blade template as a PDF. This allows you to leverage Laravel’s powerful templating system for dynamic content like invoices or reports.
- What are the differences between DomPDF and Snappy (WkHTMLtoPDF) in this package?
- DomPDF is lightweight and pure PHP, ideal for simple PDFs but with limited CSS support. Snappy (WkHTMLtoPDF) renders HTML/CSS like a browser, offering better layout fidelity but requiring system dependencies (e.g., `wkhtmltopdf`). Choose DomPDF for zero-config simplicity or Snappy for complex designs.
- How do I handle PDF generation asynchronously for high-traffic Laravel apps?
- Use Laravel queues with `Pdf::queue()` to offload PDF generation to a worker. Example: `Pdf::view('pdf.view')->queue('invoice.pdf');`. This prevents timeouts and improves scalability. Pair with `shouldQueue()` for dynamic control.
- Does spatie/laravel-pdf support modern CSS features like Flexbox or Grid?
- Only if using Chromium-based drivers like Browsershot or Gotenberg. DomPDF lacks full CSS support, while Snappy and Browsershot render modern CSS accurately. For advanced layouts, prefer Browsershot or Snappy over DomPDF.
- How can I test PDF generation in Laravel’s testing environment?
- Use `Pdf::fake()` to mock PDF generation in unit tests, preventing actual file creation. For end-to-end tests, use Laravel’s HTTP testing tools to simulate PDF downloads. Example: `Pdf::fake(); $response = $this->get('/download-pdf'); $response->assertDownload();`.
- What are the system requirements for Snappy (WkHTMLtoPDF) in production?
- Snappy requires `wkhtmltopdf` installed on your server (Linux: `sudo apt-get install wkhtmltopdf`; macOS: `brew install wkhtmltopdf`). Test in staging first to ensure compatibility. For Docker, use the `spatie/laravel-snappy` package or install `wkhtmltopdf` in your container.
- Can I customize the PDF generation process beyond basic usage?
- Yes, the package is extensible. Bind custom PDF classes or engines via Laravel’s service container. Override default settings (e.g., margins, page size) using chainable methods like `->format('a4')->margin(10)`. For advanced workflows, listen to `PdfGenerated` events to post-process PDFs.
- Are there alternatives to spatie/laravel-pdf for PDF generation in Laravel?
- Yes, alternatives include `barryvdh/laravel-dompdf` (DomPDF-focused) or `mike42/laravel-export` (for Excel/PDF exports). However, `spatie/laravel-pdf` stands out for its multi-engine support, Blade integration, and async capabilities. Evaluate based on your need for simplicity (DomPDF) or advanced features (Snappy/Browsershot).