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.
Pros:
knplabs/snappy (via GeneratorInterface), enabling seamless adoption in Laravel apps using packages like barryvdh/laravel-dompdf or custom PDF generation logic.--timeout, --attachment, --xmp-metadata), allowing fine-grained control over PDF generation (e.g., metadata, attachments, accessibility tags).symfony/process (v6.2+), ensuring compatibility with Laravel’s service container and event systems (e.g., logging, queues).Cons:
Pdf class as a singleton or context-bound service for dependency injection.$pdf->disableTimeout()) to avoid conflicts with Laravel Queues (e.g., shouldQueue()).getOutput() or generateFromHtml().// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton(Pdf::class, function ($app) {
return new Pdf(config('weasyprint.binary_path'));
});
}
// routes/web.php
Route::get('/invoice/{id}', function ($id) {
$pdf = app(Pdf::class);
$html = view('invoices.pdf', ['id' => $id])->render();
return response($pdf->getOutput($html))
->header('Content-Type', 'application/pdf');
});
apt-get install python3-weasyprint)./usr/local/bin/weasyprint is fragile; use environment variables or config files (e.g., .env):
WEASYPRINT_BINARY=/usr/local/bin/weasyprint
setTimeout() or disable in queued jobs.--no-http-redirects can be enabled to mitigate SSRF risks).style tags). Sanitize input or use a whitelist (e.g., Laravel’s Purifier).symfony/process (patched for CVE-2024-51736) and WeasyPrint (track for updates).knplabs/snappy or dompdf that need migration?Pdf class as a singleton or context-bound service for DI.disableTimeout() in queued jobs to avoid conflicts with Laravel’s queue workers (e.g., shouldQueue()).getOutput() or generateFromHtml().response()->stream() or Storage::disk('public')->put() for file downloads.symfony/process for subprocess management, ensuring consistency with Laravel’s Process facade.Pdf class in unit tests using PHPUnit’s createMock() or Laravel’s Mockery.knplabs/snappy, dompdf, or custom solutions)./reports/pdf) with php-weasyprint.snappy calls in controllers/services with php-weasyprint.php-weasyprint-compatible CSS (e.g., avoid unsupported properties).disableTimeout() and monitor performance.python:3.11-slim) or system package manager (e.g., apt-get install python3-weasyprint) for consistency.composer require php:^8.3 if needed.v1.x of this package (last Symfony 6.x compatible version).@font-face with local files)..env or config files.SnappyPdf with Pontedilana\PhpWeasyPrint\Pdf in services/controllers.Pdf class to test integration with services.How can I help you explore Laravel packages today?