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 Pdf Laravel Package

spatie/laravel-pdf

Generate PDFs from Laravel Blade views with a simple fluent API. Choose drivers like Browsershot/Chromium, Gotenberg, Cloudflare Browser Run, WeasyPrint, DOMPDF, or chrome-php. Use modern CSS, set page formats, and stream or save PDFs.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Laravel-native: Seamlessly integrates with Laravel’s ecosystem (Blade, Facades, HTTP responses), reducing friction in adoption.
    • Multi-driver support: Offers flexibility (Chromium, Docker, Python, PHP-only) to align with infrastructure constraints (e.g., DOMPDF for zero-dependency environments, Browsershot for modern CSS).
    • Extensible: Supports headers/footers, metadata, conditional formatting, and accessibility (tagged PDFs), enabling compliance and branding needs.
    • Testing utilities: Built-in PDF faking and assertions simplify test coverage for critical workflows (e.g., invoices, reports).
    • Laravel Boost compatibility: Enhances AI-assisted development (e.g., GitHub Copilot) for PDF generation logic.
  • Cons:

    • Driver complexity: Requires selecting/managing external dependencies (e.g., Docker for Gotenberg, Python for WeasyPrint), adding operational overhead.
    • Feature parity gaps: DOMPDF lacks advanced features (e.g., @pageNumber, scaling), necessitating driver-specific logic.
    • Resource intensity: Chromium-based drivers (Browsershot) demand higher memory/CPU, impacting scaling for high-volume PDF generation.

Integration Feasibility

  • Laravel Compatibility:
    • Works with Laravel 10+ (tested up to 12.x). Backward compatibility with older versions may require adjustments.
    • Integrates with Laravel’s HTTP responses, queues, and storage systems (e.g., saving to storage/app/pdf).
  • Dependency Conflicts:
    • Potential conflicts with existing PDF libraries (e.g., barryvdh/laravel-dompdf) or Chromium-based tools (e.g., Puppeteer).
    • Mitigation: Use Composer’s replace or conflict directives in composer.json to enforce single-source usage.
  • Database/ORM:
    • No direct DB dependencies, but PDF generation may trigger heavy queries (e.g., rendering complex reports). Optimize with query caching or background jobs.

Technical Risk

  • High:
    • Driver failures: Chromium/Docker dependencies may break in CI/CD or production (e.g., missing puppeteer, Docker daemon issues).
    • CSS rendering quirks: Modern CSS (e.g., Grid/Flexbox) may render inconsistently across drivers (test thoroughly with target templates).
    • Performance: Large PDFs (e.g., multi-page reports) could cause timeouts or memory limits (monitor with memory_get_usage()).
  • Medium:
    • Accessibility: Tagged PDFs require validation (e.g., screen reader testing) to ensure compliance (WCAG/ADA).
    • Internationalization: PDF metadata/fonts may need locale-specific handling (e.g., CJK character support).
  • Low:
    • License: MIT license poses no legal risks.
    • Maintenance: Spatie’s active maintenance (recent 2026 release) reduces long-term risk.

Key Questions

  1. Driver Selection:
    • Which driver aligns with our infrastructure (e.g., DOMPDF for air-gapped systems, Browsershot for dev environments)?
    • Are we prepared to manage Docker/Gotenberg in production?
  2. Scaling:
    • How will we handle concurrent PDF generation (e.g., queue workers, horizontal scaling)?
    • What are the memory/CPU limits for our target PDF sizes?
  3. Testing:
    • How will we validate PDF output (visual regression, accessibility, content accuracy)?
    • Are we using the testing utilities (e.g., Pdf::fake()) in our CI pipeline?
  4. Fallbacks:
    • What’s the backup plan if the primary driver fails (e.g., fallback to DOMPDF)?
  5. Cost:
    • Are there hidden costs (e.g., Cloudflare Browser Run API limits, Docker resource usage)?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Blade Templates: Native support for Blade views simplifies PDF generation (e.g., Pdf::view('invoices.show')).
    • HTTP Responses: Direct integration with Laravel’s response system (e.g., return Pdf::download()).
    • Queues: Pair with Laravel Queues for async generation (e.g., Pdf::view()->toQueue()).
    • Storage: Save to storage/app/pdf or cloud storage (S3) via Laravel Filesystem.
  • Frontend/Backend:
    • Frontend: Trigger PDF generation via API endpoints (e.g., POST /pdfs/invoice).
    • Backend: Use in CLI commands (e.g., artisan pdf:generate:batch) or scheduled jobs (e.g., nightly reports).
  • Third-Party Tools:
    • Docker: Required for Gotenberg driver (ensure Docker daemon is available in all environments).
    • Python: Required for WeasyPrint (manage via pyenv or system packages).
    • Chromium: Required for Browsershot (install via npm or system package manager).

Migration Path

  1. Pilot Phase:
    • Start with a single driver (e.g., DOMPDF for simplicity) and a non-critical feature (e.g., user-generated certificates).
    • Test with a subset of templates to identify rendering issues.
  2. Gradual Rollout:
    • Replace legacy PDF generation (e.g., custom PHP libraries, tcpdf) with spatie/laravel-pdf.
    • Use feature flags to toggle between old/new implementations.
  3. Driver Migration:
    • Migrate from DOMPDF to Browsershot for templates requiring modern CSS.
    • Containerize Gotenberg if using Docker-based driver.
  4. Deprecation:
    • Phase out unsupported drivers (e.g., chrome-php/chrome) in favor of maintained options.

Compatibility

  • Laravel Versions:
  • PHP Versions:
    • Requires PHP 8.1+. Ensure compatibility with your app’s PHP version.
  • Template Compatibility:
    • Audit existing Blade templates for CSS/HTML that may break across drivers (e.g., absolute positioning, fixed widths).
    • Use the dump() method to debug rendering issues.
  • Dependency Conflicts:
    • Run composer why-not spatie/laravel-pdf to check for conflicts.
    • Use composer require spatie/laravel-pdf --with-all-dependencies to preemptively resolve issues.

Sequencing

  1. Setup:
    • Install the package: composer require spatie/laravel-pdf.
    • Publish config: php artisan vendor:publish --provider="Spatie\Pdf\PdfServiceProvider".
    • Install Laravel Boost: php artisan boost:install.
  2. Configuration:
    • Set default driver in .env (e.g., PDF_DRIVER=dompdf).
    • Configure driver-specific options (e.g., Chromium path for Browsershot).
  3. Development:
    • Create Blade templates for PDFs (e.g., resources/views/pdf/invoice.blade.php).
    • Implement a base controller/service for PDF generation (e.g., app/Services/PdfService.php).
  4. Testing:
    • Write unit tests using Pdf::fake().
    • Add visual regression tests (e.g., compare PDFs with golden masters).
  5. Deployment:
    • Ensure Docker/Python/Chromium dependencies are available in staging/production.
    • Monitor PDF generation logs for failures (e.g., driver timeouts).

Operational Impact

Maintenance

  • Proactive Tasks:
    • Driver Updates: Monitor Spatie’s releases for driver updates (e.g., Browsershot v5 compatibility).
    • Dependency Management: Regularly update puppeteer, poppler-utils, and other driver dependencies.
    • Template Audits: Review Blade templates for CSS/HTML that may break across driver versions.
  • Reactive Tasks:
    • Debugging: Use Pdf::dump() to diagnose rendering issues.
    • Fallbacks: Implement a backup driver (e.g., DOMPDF) for critical paths.
  • Documentation:
    • Maintain a runbook for common issues (e.g., "Docker not running → restart service").
    • Document driver-specific quirks (e.g., "WeasyPrint fails on complex tables").

Support

  • Developer Onboarding:
    • Train teams on driver selection (e.g., "Use Browsershot for invoices, DOMPDF for emails").
    • Document the Pdf facade vs. pdf() helper (e.g., "Use facade for config, helper for brevity").
  • User Support:
    • Provide clear error messages (e.g., "PDF generation failed: missing Chromium").
    • Offer a support email/channel for PDF-related issues.
  • SLA Impact:
    • PDF generation may add latency (e.g., Chromium startup time). Set realistic SLAs for async jobs.

Scaling

  • **Horizontal Scaling
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai