pontedilana/php-weasyprint
Laravel-friendly PHP wrapper for WeasyPrint to render HTML/CSS into high-quality PDFs (and images) via a simple API. Ideal for invoices, reports, and templated documents, with options for assets, headers/footers, and configuration.
pip install weasyprint).exec() or shell_exec() for subprocess calls (security implications; see Technical Risk).PdfGeneratorService) with dependency injection.GeneratePdfJob extending ShouldQueue).Storage::disk('public')->put()).cairo, pango), or Docker/host environment mismatches.php:8.2-apache + Python layer) or platform-specific deployment (e.g., Heroku Python buildpack).exec() if input sanitization is lax (e.g., URL/HTML injection).Str::of() for sanitization, or restrict to trusted sources.WeasyPrint.Http::get($url)->body()).GeneratePdfJob).spatie/laravel-medialibrary).exec() calls (simplest but riskier).app/Services/PdfGenerator.php) wrapping Pontedilana\WeasyPrint\WeasyPrint.public function generateFromHtml(string $html, string $outputPath): void
{
$weasyPrint = new WeasyPrint();
$weasyPrint->fromHtml($html)->save($outputPath);
}
GeneratePdfJob) with retries.FROM php:8.2-apache as php
FROM python:3.9-slim as python
COPY --from=python /usr/local/bin/weasyprint /usr/local/bin/
generateFromUrl()).requirements.txt or pyproject.toml.composer.json with pontedilana/php-weasyprint + symfony/process.Process::mustRun()->getOutput()).cairo, pango), memory limits, or HTML parsing errors.weasyprint --version
python -c "import weasyprint; print(weasyprint.__version__)"
position: fixed").PCNTL or pm2).weasyprint --enable-internal-links).cache()->remember()) for repeated PDFs.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Python/WeasyPrint missing | PDF generation fails silently | Health checks, Docker images with preinstalled deps |
| HTML parsing errors | Corrupted PDFs | Validate HTML before processing |
| High memory usage | Worker crashes | Set memory limits (ulimit -Sv 512M) |
| Queue job timeouts | Stuck PDFs | Increase timeout, retry logic |
| CSS/JS incompatibility | Rendering issues | Test with real templates, document limitations |
WeasyPrint::fromHtml()).How can I help you explore Laravel packages today?