daif / chrome-pdf-bundle
A Symfony bundle for generating PDFs and screenshots using a local Chrome/Chromium binary via Chrome DevTools Protocol, with a clean, builder-based API.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/daif/chrome-pdf-bundle
Requires
- php: >=8.1
- ext-filter: *
- ext-json: *
- chrome-php/chrome: ^1.15
- league/commonmark: ^2.8
- psr/container: ^2.0
- psr/log: ^3.0
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/filesystem: ^6.4 || ^7.0 || ^8.0
- symfony/http-foundation: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
- symfony/service-contracts: ^3.6
Requires (Dev)
- ext-mbstring: *
- async-aws/s3: ^2.6
- friendsofphp/php-cs-fixer: ^3.93
- league/flysystem: ^3.29
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^10.5.46
- shipmonk/composer-dependency-analyser: ^1.8
- symfony/asset: ^6.4 || ^7.0 || ^8.0
- symfony/asset-mapper: ^6.4 || ^7.0 || ^8.0
- symfony/console: ^6.4 || ^7.0 || ^8.0
- symfony/css-selector: ^6.4 || ^7.0 || ^8.0
- symfony/dom-crawler: ^6.4 || ^7.0 || ^8.0
- symfony/error-handler: ^6.4 || ^7.0 || ^8.0
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/http-client: ^6.4 || ^7.0 || ^8.0
- symfony/monolog-bundle: ^3.10 || ^4.0
- symfony/routing: ^6.4 || ^7.0 || ^8.0
- symfony/stopwatch: ^6.4 || ^7.0 || ^8.0
- symfony/twig-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/var-dumper: ^6.4 || ^7.0 || ^8.0
- symfony/yaml: ^6.4 || ^7.0 || ^8.0
- twig/twig: ^3.14
Suggests
- async-aws/s3: Upload any file to aws s3 compatible endpoints supporting multi part upload without memory overhead.
- league/flysystem-bundle: Upload any file using this filesystem abstraction package.
- monolog/monolog: Enables logging througout the generating process.
- symfony/monolog-bundle: Enables logging througout the generating process.
- symfony/routing: Allows you to use route() method to generate PDFs from Symfony routes.
- symfony/twig-bundle: Allows you to use Twig to render templates into PDF.
This package is auto-updated.
Last update: 2026-02-11 22:22:10 UTC
README
WYSIWYPDF -- What You See Is What You PDF
The dockerless PDF generator for Symfony. Just Chrome. No containers, no wrapping, no kidding.
composer require daif/chrome-pdf-bundle
Why this bundle?
I wanted to use sensiolabs/gotenberg-bundle -- it's a great and complete Symfony bundle for PDF generation. But it relies on Gotenberg, which requires a running Docker container.
In my case, working in on-premise environments (banking, insurance, regulated industries), Docker is simply not available on production servers. Security policies and infrastructure constraints prevent running containers.
Yet these same machines almost always have a browser installed, or can easily add one. Google Chrome and Chromium are well-maintained, widely trusted, and available on virtually every Linux distribution through standard package managers.
So I built ChromePdfBundle: the same clean builder-based API, but driving Chrome/Chromium directly via the Chrome DevTools Protocol -- no Docker, no external service, no extra infrastructure.
| Docker-based solutions | ChromePdfBundle |
|---|---|
| Require Docker + a running container | Requires only a Chrome/Chromium binary |
| HTTP calls to an external service | Direct communication via CDP |
| Extra infrastructure to maintain | Uses a browser already on the system |
| Not usable in Docker-free environments | Works everywhere Chrome runs |
How to install
Requirements
- PHP 8.1+
- Symfony 6.4 / 7.x / 8.x
- Google Chrome or Chromium installed on the system (see Chrome installation guide)
composer require daif/chrome-pdf-bundle
This installs the bundle along with chrome-php/chrome, the PHP library used to communicate with Chrome via the DevTools Protocol.
Enable the bundle
If not using Symfony Flex, manually register the bundle:
// config/bundles.php return [ // ... Daif\ChromePdfBundle\DaifChromePdfBundle::class => ['all' => true], ];
Configuration
Create a minimal configuration:
# config/packages/daif_chrome_pdf.yaml daif_chrome_pdf: assets_directory: '%kernel.project_dir%/assets'
The bundle will automatically detect Chrome/Chromium on your system. You can also specify the binary path explicitly:
daif_chrome_pdf: chrome_binary: '/usr/bin/google-chrome'
Basic Usage
PDF from Twig template
namespace App\Controller; use Daif\ChromePdfBundle\ChromePdfInterface; use Symfony\Component\HttpFoundation\Response; class InvoiceController { public function generateInvoice(ChromePdfInterface $chromePdf): Response { return $chromePdf->html() ->content('invoice.html.twig', [ 'invoice' => $invoice, ]) ->generate() ->stream() ; } }
PDF from URL
use Daif\ChromePdfBundle\ChromePdfInterface; class ReportController { public function generateReport(ChromePdfInterface $chromePdf): Response { return $chromePdf->url() ->url('https://example.com/report') ->generate() ->stream() ; } }
PDF from Markdown
use Daif\ChromePdfBundle\ChromePdfInterface; class DocController { public function generateDoc(ChromePdfInterface $chromePdf): Response { return $chromePdf->markdown() ->wrapper('wrapper.html.twig') ->files('content.md') ->generate() ->stream() ; } }
Screenshot
use Daif\ChromePdfBundle\ChromeScreenshotInterface; class ScreenshotController { public function capture(ChromeScreenshotInterface $chromeScreenshot): Response { return $chromeScreenshot->html() ->content('page.html.twig') ->generate() ->stream() ; } }
Twig assets
If a template needs to link to a static asset (image, CSS, font), use the {{ chrome_pdf_asset() }} Twig function:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <title>My PDF</title> </head> <body> <img src="{{ chrome_pdf_asset('img/logo.png') }}" alt="Logo"/> </body> </html>
Advanced Usage
- Chrome installation guide
- Configuration
- Processing (saving, streaming, S3...)
- Working with assets
- Working with fonts
Screenshot
Licence
MIT License (MIT): see the License File for more details.