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
Php Weasyprint

Php Weasyprint Laravel Package

pontedilana/php-weasyprint

PHP wrapper for WeasyPrint (v60+) to generate PDFs from URLs or HTML. Snappy-like API with output streaming or file generation, supports WeasyPrint CLI options (encoding, media type, stylesheets, attachments) and timeouts.

View on GitHub
Deep Wiki
Context7

PHP library allowing PDF generation or snapshot from an URL or an HTML page. Wrapper for Kozea/WeasyPrint

Frequently asked questions about Php Weasyprint
How do I install and set up PhpWeasyPrint in a Laravel project?
Run `composer require pontedilana/php-weasyprint` to install the package. WeasyPrint (Python-based, v60+) must also be installed on your server. Bind the `Pdf` class in Laravel’s service container (e.g., `app()->singleton(Pdf::class, fn() => new Pdf(config('weasyprint.binary_path')))`) to use dependency injection.
Can I use PhpWeasyPrint to generate PDFs from Blade templates in Laravel?
Yes. Render your Blade template to HTML (e.g., `$html = view('invoice')->render()`) and pass it to `getOutput($html)` or `generateFromHtml()`. Stream the output directly in a route or save it to disk.
What Laravel versions does PhpWeasyPrint support?
PhpWeasyPrint works with Laravel 8.x, 9.x, and 10.x. It relies on Symfony Process (v6.2+), which is compatible with these Laravel versions. Test thoroughly if using older Laravel 7.x with custom configurations.
How do I handle timeouts for PDF generation in production?
The default 10-second timeout may need adjustment for complex PDFs. Use `$pdf->setTimeout(30)` to increase it or disable it entirely (`$pdf->disableTimeout()`) for queued jobs. Monitor process execution time in production to avoid hanging requests.
Is PhpWeasyPrint a drop-in replacement for KnpLabs/snappy in Laravel?
Yes, it implements the same `GeneratorInterface` as Snappy, so you can replace Snappy with PhpWeasyPrint in Laravel apps using packages like `barryvdh/laravel-dompdf` or custom PDF logic. Check the [differences section](https://github.com/pontedilana/php-weasyprint#differences-with-snappy) for WeasyPrint-specific limitations.
How do I configure WeasyPrint options like CSS or attachments?
Use `$pdf->setOption()` to pass WeasyPrint CLI arguments. For example, `$pdf->setOption('stylesheet', ['/path/to/style.css'])` or `$pdf->setOption('attachment', ['/path/to/image.png'])` to include stylesheets or attachments. Run `weasyprint -h` for a full list of supported options.
Can I generate PDFs from remote URLs with PhpWeasyPrint?
Yes. Use `$pdf->getOutput('https://example.com')` to fetch and render a URL directly. By default, it follows redirects, but you can disable this with `$pdf->setOption('no-http-redirects', true)` to mitigate SSRF risks.
What are the infrastructure requirements for PhpWeasyPrint?
You need Python 3.8+ and WeasyPrint (≥60.0) installed on your server. For Docker, include `python3-weasyprint` in your image. Avoid hardcoding the binary path; use environment variables (e.g., `WEASYPRINT_BINARY=/usr/local/bin/weasyprint`) or Laravel config files.
How do I handle security risks like CSS/JS injection in dynamic HTML?
Sanitize user-provided HTML/CSS before passing it to PhpWeasyPrint. Use Laravel’s `Purifier` package or a whitelist to strip unsafe tags. For metadata, avoid exposing sensitive data in PDF attachments or XMP tags.
Are there alternatives to PhpWeasyPrint for PDF generation in Laravel?
Yes. Consider `barryvdh/laravel-dompdf` (HTML-to-PDF with Dompdf), `spatie/laravel-pdf` (wrapper for Dompdf/Snappy), or `mike42/laravel-puppeteer` (headless Chrome). PhpWeasyPrint excels for CSS3-heavy PDFs but requires Python/WeasyPrint setup.
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