dreadnip/chrome-pdf-bundle
Symfony bundle that uses chrome-php/chrome to render HTML to PDF via Chrome/Chromium. Configure the Chrome binary via env, then generate PDFs from HTML with the PdfGenerator service or customize via the BrowserFactory for advanced options.
Architecture Fit
The dreadnip/chrome-pdf-bundle is a lightweight Symfony bundle that wraps chrome-php/chrome, a headless Chrome automation library for PDF generation. Its architecture is modular and aligns well with Laravel applications requiring dynamic PDF generation, particularly those leveraging Symfony components (e.g., Laravel 10+ with Symfony 6.4+). The bundle abstracts Chrome/Chromium setup and PDF generation logic, reducing boilerplate while allowing customization via options (e.g., print settings, browser flags). Key strengths include:
Integration Feasibility Integration is straightforward for Laravel applications using Symfony components. The bundle requires:
symfony/process).CHROME_BINARY environment variable. Docker or CI environments may need additional setup (e.g., libx11, libgbm).spatie/laravel-symfony-bundle or manually register the bundle in config/bundles.php.Technical Risk
chrome-php/chrome, which is actively maintained but may introduce breaking changes. Monitor updates.Key Questions
symfony/process, symfony/http-client).libx11) available in all environments?Stack Fit
spatie/laravel-symfony-bundle for seamless integration.symfony/process, symfony/http-client, and twig. Ensure these are installed and version-compatible.Migration Path
chromium:latest).RUN apt-get update && apt-get install -y chromium libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libasound2
composer.json:
composer require dreadnip/chrome-pdf-bundle
config/bundles.php:
return [
// ...
Dreadnip\ChromePdfBundle\ChromePdfBundle::class => ['all' => true],
];
.env:
CHROME_BINARY="/usr/bin/chromium-browser"
php artisan vendor:publish --tag=chrome-pdf-config
PdfGenerator into controllers or commands:
use Dreadnip\ChromePdfBundle\Service\PdfGenerator;
public function generatePdf(PdfGenerator $pdfGenerator) {
$html = view('pdf.template')->render();
$path = $pdfGenerator->generate($html, 'path/to/output.pdf');
}
Compatibility
Sequencing
composer.json and register it.Maintenance
dreadnip/chrome-pdf-bundle and chrome-php/chrome for breaking changes.composer.json to avoid unexpected updates:
"dreadnip/chrome-pdf-bundle": "^0.7",
"chrome-php/chrome": "^1.5"
.env) to avoid hardcoding.CHROME_BINARY=/usr/bin/chromium-browser
CHROME_PDF_TIMEOUT=30
Log facade:
use Psr\Log\LoggerInterface;
public function generatePdf(PdfGenerator $pdfGenerator, LoggerInterface $logger) {
try {
$path = $pdfGenerator->generate($html, 'output.pdf');
} catch (\Exception $e) {
$logger->error('PDF generation failed', ['error' => $e->getMessage()]);
throw $e;
}
}
chrome-php/chrome (e.g., new options, deprecations).Support
CHROME_BINARY points to a valid path. Use absolute paths in .env.timeout option or optimize HTML/CSS for faster rendering.libx11) are installed in all environments.memory_limit in php.ini or use smaller chunks for batch processing.How can I help you explore Laravel packages today?