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

Html2Pdf Laravel Package

spipu/html2pdf

HTML2PDF converts HTML/CSS into PDF documents with a straightforward PHP API. Supports page setup, headers/footers, images, fonts and Unicode, tables, and basic CSS styling. Useful for invoices, reports, and print-ready exports in web apps.

View on GitHub
Deep Wiki
Context7

OFFICIAL PROJECT | HTML to PDF converter written in PHP

Frequently asked questions about Html2Pdf
How do I install spipu/html2pdf in a Laravel project?
Run `composer require spipu/html2pdf` in your project root. Ensure PHP 7.2+ and extensions `gd` and `mbstring` are enabled. No additional Laravel-specific setup is required beyond Composer installation.
Can I use this package to generate PDFs from Laravel Blade templates?
Yes. Pass your Blade-generated HTML to the `Html2Pdf` class, ensuring the HTML is optimized for PDF rendering (e.g., avoid complex CSS or WYSIWYG-generated markup). Use `@include('pdf.template')` with dynamic data.
Does spipu/html2pdf support Laravel Queues for async PDF generation?
Absolutely. Wrap PDF generation in a Laravel job (e.g., `GeneratePdfJob`) and dispatch it via the queue system. This is critical for performance, especially for user-triggered actions like invoice downloads.
What Laravel versions does spipu/html2pdf support?
The package itself requires PHP 7.2–8.4, but it integrates seamlessly with all modern Laravel versions (6.x–11.x). No Laravel-specific dependencies exist, so version compatibility is broad.
How do I handle dynamic data (e.g., user-specific invoices) in PDF templates?
Use Laravel’s service container to bind `Html2Pdf` and pass dynamic data via Blade variables (e.g., `$invoice->amount`). Store templates in `resources/views/pdf/` and include them with `@include('pdf.invoice', ['data' => $invoice])`.
Are there performance concerns with spipu/html2pdf in production?
Yes, PDF generation can be resource-intensive. Mitigate this by using Laravel Queues + Redis for async processing, caching pre-generated templates, or offloading to a microservice. Test under load with tools like Laravel Dusk.
What if Ghostscript or libpng dependencies fail in production?
Use Docker (e.g., Laradock) to isolate dependencies. Avoid conflicts with `dompdf` by ensuring only one HTML-to-PDF package is installed. For system installs, verify Ghostscript and `libpng` are properly configured in your production environment.
Can I use spipu/html2pdf for batch processing (e.g., nightly reports)?
Yes, but design for scalability. Queue batch jobs with `GeneratePdfJob::dispatch($data)` and process them asynchronously. Monitor progress via Laravel Horizon. For large volumes, consider a dedicated microservice.
How do I test PDF generation in Laravel?
Unit-test with Mockery to mock the `Html2Pdf` class. For end-to-end tests, use Laravel Dusk to verify PDF output or tools like `pdf-diff` to compare generated files against expected templates. Test edge cases like Unicode or complex tables.
What are the alternatives to spipu/html2pdf for Laravel?
Consider `dompdf` (lighter, no Ghostscript), `wkhtmltopdf` (browser-based, higher quality), or `barryvdh/laravel-dompdf` (Laravel wrapper for dompdf). Choose based on dependency constraints, performance needs, and output quality requirements.
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views