PHPackages                             sylius/pdf-generation-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. sylius/pdf-generation-bundle

ActiveSymfony-bundle[PDF &amp; Document Generation](/categories/documents)

sylius/pdf-generation-bundle
============================

PDF generation bundle with swappable renderer abstraction.

v1.0.0(6d ago)034↑2900%1MITPHPPHP &gt;=8.2CI passing

Since Mar 18Pushed 5d ago1 watchersCompare

[ Source](https://github.com/Sylius/PdfGenerationBundle)[ Packagist](https://packagist.org/packages/sylius/pdf-generation-bundle)[ GitHub Sponsors](https://github.com/sylius)[ RSS](/packages/sylius-pdf-generation-bundle/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (21)Versions (2)Used By (0)

 [    ![Sylius Logo.](https://camo.githubusercontent.com/ea9dddc934264aa7ec01cf3202c500f3d8b04448bce2571bdc74230efddda88f/68747470733a2f2f6d656469612e73796c6975732e636f6d2f73796c6975732d6c6f676f2d3830302e706e67)  ](https://sylius.com)

PdfGenerationBundle
===================

[](#pdfgenerationbundle)

A Symfony bundle providing a swappable PDF generation abstraction with context-based adapter selection.

Overview
--------

[](#overview)

This bundle decouples PDF rendering from application-specific logic by providing a clean adapter-based architecture. Choose between built-in adapters or register your own - each rendering context can use a different adapter with its own configuration.

**Built-in adapters:**

AdapterLibraryRequires`knp_snappy`[knplabs/knp-snappy-bundle](https://github.com/KnpLabs/KnpSnappyBundle)`wkhtmltopdf` binary`dompdf`[dompdf/dompdf](https://github.com/dompdf/dompdf)Nothing (pure PHP)`gotenberg`[gotenberg/gotenberg-php](https://github.com/gotenberg/gotenberg-php)Running Gotenberg container**Supported storage backends:**

Storage typeLibraryRequires`filesystem`[symfony/filesystem](https://github.com/symfony/filesystem)Nothing (included by default)`flysystem`[league/flysystem-bundle](https://github.com/thephpleague/flysystem-bundle)A configured Flysystem filesystem`gaufrette`[knplabs/knp-gaufrette-bundle](https://github.com/KnpLabs/KnpGaufretteBundle)A configured Gaufrette filesystemInstallation
------------

[](#installation)

```
composer require sylius/pdf-generation-bundle
```

Install an adapter library depending on your needs:

```
# For wkhtmltopdf-based rendering
composer require knplabs/knp-snappy-bundle

# For pure PHP rendering (no external binary)
composer require dompdf/dompdf

# For Gotenberg (Docker-based headless Chromium)
composer require gotenberg/gotenberg-php
```

Register the bundle if your application doesn't use Symfony Flex:

```
// config/bundles.php
return [
    // ...
    Sylius\PdfGenerationBundle\SyliusPdfGenerationBundle::class => ['all' => true],
];
```

Configuration
-------------

[](#configuration)

```
# config/packages/sylius_pdf_generation.yaml
sylius_pdf_generation:
    gotenberg:
        base_url: 'http://localhost:3000'
    default:
        adapter: dompdf
        storage:
            type: filesystem
            directory: '%kernel.project_dir%/var/pdf'
    contexts:
        invoice:
            adapter: knp_snappy
            storage:
                type: flysystem
                filesystem: 'default.storage'
                prefix: 'invoices'
                local_cache_directory: '%kernel.project_dir%/var/pdf_cache'
```

KeyDescription`default`Configuration for the default context (used when no context is specified).`contexts`Named contexts, each with its own adapter and optional storage override.`adapter`Adapter name: `knp_snappy`, `dompdf`, `gotenberg`, or a custom adapter key.`gotenberg.base_url`URL of the Gotenberg server (default: `http://localhost:3000`).`storage.type`Storage backend: `filesystem` (default), `flysystem`, or `gaufrette`.`storage.filesystem`Flysystem/Gaufrette filesystem service ID (e.g. `default.storage`).`storage.prefix`Path prefix for Flysystem/Gaufrette storage.`storage.directory`Local directory path (required for `filesystem` type only).`storage.local_cache_directory`Local cache path for `resolveLocalPath()` (Flysystem/Gaufrette only).Each context (including `default`) can override `storage`. When omitted, the default storage configuration is inherited. The context name `default` is reserved and cannot be used inside `contexts`.

Usage
-----

[](#usage)

### Rendering HTML to PDF

[](#rendering-html-to-pdf)

Inject `HtmlToPdfRendererInterface` and call `render()`:

```
use Sylius\PdfGenerationBundle\Core\Renderer\HtmlToPdfRendererInterface;

final class InvoiceController
{
    public function __construct(
        private readonly HtmlToPdfRendererInterface $renderer,
    ) {}

    public function download(): Response
    {
        $pdfContent = $this->renderer->render('Invoice #001');

        return new Response($pdfContent, 200, [
            'Content-Type' => 'application/pdf',
        ]);
    }
}
```

### Rendering Twig templates to PDF

[](#rendering-twig-templates-to-pdf)

Inject `TwigToPdfRendererInterface` to render a Twig template directly:

```
use Sylius\PdfGenerationBundle\Core\Renderer\TwigToPdfRendererInterface;

$pdfContent = $this->twigRenderer->render(
    'invoice/template.html.twig',
    ['invoiceNumber' => '001'],
);
```

### Using contexts

[](#using-contexts)

Pass a context name to route rendering to a specific adapter:

```
// Uses the 'invoice' context adapter
$pdfContent = $this->renderer->render($html, 'invoice');
```

### Managing PDF files

[](#managing-pdf-files)

Use `PdfFileGeneratorInterface` to generate and persist PDF files:

```
use Sylius\PdfGenerationBundle\Core\Generator\PdfFileGeneratorInterface;

$pdfFile = $this->generator->generate('invoice_001.pdf', $pdfContent, 'invoice');

$pdfFile->filename();  // 'invoice_001.pdf'
$pdfFile->storagePath();  // storage-relative path (e.g. '/path/to/private/invoices/invoice_001.pdf')
```

Or use `PdfFileManagerInterface` directly for fine-grained control:

```
use Sylius\PdfGenerationBundle\Core\Filesystem\Manager\PdfFileManagerInterface;
use Sylius\PdfGenerationBundle\Core\Model\PdfFile;

// Save
$this->manager->save(new PdfFile('report.pdf', $content), 'invoice');

// Check existence
$this->manager->has('report.pdf', 'invoice'); // true

// Retrieve
$file = $this->manager->get('report.pdf', 'invoice');

// Remove
$this->manager->remove('report.pdf', 'invoice');

// Resolve absolute local path (e.g. for email attachments)
$localPath = $this->manager->resolveLocalPath('report.pdf', 'invoice');
```

Extending the bundle
--------------------

[](#extending-the-bundle)

### Custom adapters

[](#custom-adapters)

#### Via PHP attribute (recommended)

[](#via-php-attribute-recommended)

```
use Sylius\PdfGenerationBundle\Core\Adapter\PdfGenerationAdapterInterface;
use Sylius\PdfGenerationBundle\Core\Attribute\AsPdfGenerationAdapter;

#[AsPdfGenerationAdapter('my_adapter')]
final class MyCustomAdapter implements PdfGenerationAdapterInterface
{
    public function generate(string $html): string
    {
        // Your implementation...
    }
}
```

#### Via service tag

[](#via-service-tag)

```
services:
    App\Pdf\MyCustomAdapter:
        tags:
            - { name: 'sylius_pdf_generation.adapter', key: 'my_adapter' }
```

Then reference it by key in configuration:

```
sylius_pdf_generation:
    default:
        adapter: my_adapter
```

Custom adapters are user-managed services - the bundle does not pass configuration options to them.

### Custom generator providers

[](#custom-generator-providers)

Generator providers create the underlying PDF library instance (e.g. a `Dompdf` or `Knp\Snappy\GeneratorInterface` object). Register a custom provider to control how the generator is instantiated:

#### Via PHP attribute

[](#via-php-attribute)

```
use Sylius\PdfGenerationBundle\Core\Attribute\AsPdfGeneratorProvider;
use Sylius\PdfGenerationBundle\Core\Provider\GeneratorProviderInterface;

#[AsPdfGeneratorProvider(adapter: 'dompdf', context: 'invoice')]
final class InvoiceDompdfProvider implements GeneratorProviderInterface
{
    public function get(string $context = 'default'): \Dompdf\Dompdf
    {
        $dompdf = new \Dompdf\Dompdf();
        // Custom setup for the invoice context...
        return $dompdf;
    }
}
```

#### Via service tag

[](#via-service-tag-1)

```
services:
    App\Pdf\InvoiceDompdfProvider:
        tags:
            - { name: 'sylius_pdf_generation.generator_provider', adapter: 'dompdf', context: 'invoice' }
```

The `adapter` must match the adapter name. The optional `context` scopes the provider to a specific context; without it, the provider is used as the default for that adapter.

### Custom options processors

[](#custom-options-processors)

Options processors configure the generator instance before PDF generation. They receive the generator object and modify it directly:

#### Via PHP attribute

[](#via-php-attribute-1)

```
use Sylius\PdfGenerationBundle\Core\Attribute\AsPdfOptionsProcessor;
use Sylius\PdfGenerationBundle\Core\Processor\OptionsProcessorInterface;

#[AsPdfOptionsProcessor(adapter: 'dompdf', context: 'invoice', priority: 10)]
final class InvoicePaperSizeProcessor implements OptionsProcessorInterface
{
    public function process(object $generator, string $context = 'default'): void
    {
        /** @var \Dompdf\Dompdf $generator */
        $generator->setOptions(new \Dompdf\Options(['defaultPaperSize' => 'a4']));
    }
}
```

#### Via service tag

[](#via-service-tag-2)

```
services:
    App\Pdf\InvoicePaperSizeProcessor:
        tags:
            - { name: 'sylius_pdf_generation.options_processor', adapter: 'dompdf', context: 'invoice', priority: 10 }
```

Tag attributes:

AttributeRequiredDescription`adapter`YesThe adapter type this processor applies to (e.g. `dompdf`, `knp_snappy`).`context`NoLimits the processor to a specific context. Omit to apply to all contexts.`priority`NoHigher values run first. Defaults to `0`.Processors without a `context` attribute run for every context of their adapter type. Context-specific processors run after the default ones.

Service reference
-----------------

[](#service-reference)

Service IDInterfaceDescription`sylius_pdf_generation.renderer.html``HtmlToPdfRendererInterface`Renders HTML string to PDF`sylius_pdf_generation.renderer.twig``TwigToPdfRendererInterface`Renders Twig template to PDF`sylius_pdf_generation.manager``PdfFileManagerInterface`Stores and retrieves PDF files`sylius_pdf_generation.generator``PdfFileGeneratorInterface`Generates and persists PDF files`sylius_pdf_generation.registry.generator_provider``GeneratorProviderRegistryInterface`Resolves generator providersAll interfaces (except internal composites) are aliased for autowiring.

License
-------

[](#license)

This bundle is released under the [MIT License](LICENSE).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance99

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

6d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/719423?v=4)[Sylius eCommerce](/maintainers/sylius)[@Sylius](https://github.com/Sylius)

![](https://www.gravatar.com/avatar/4b4a5a1a9293502aa8573551fab020963a9050c5cca4524433b6d94214d3b480?d=identicon)[GSadee](/maintainers/GSadee)

---

Top Contributors

[![NoResponseMate](https://avatars.githubusercontent.com/u/9448101?v=4)](https://github.com/NoResponseMate "NoResponseMate (26 commits)")

---

Tags

symfonypdf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sylius-pdf-generation-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/sylius-pdf-generation-bundle/health.svg)](https://phpackages.com/packages/sylius-pdf-generation-bundle)
```

###  Alternatives

[sensiolabs/gotenberg-bundle

A Symfony bundle that provides seamless integration with Gotenberg for generating PDFs and screenshots from various sources (HTML, Markdown, Office documents, URLs) with a clean, builder-based API.

211170.3k2](/packages/sensiolabs-gotenberg-bundle)[nucleos/dompdf-bundle

This bundle provides a wrapper for using dompdf inside symfony.

54841.3k1](/packages/nucleos-dompdf-bundle)[bobv/latex-bundle

Latex and pdf generator for Symfony 2

2432.4k](/packages/bobv-latex-bundle)[ensepar/html2pdf-bundle

Use HTML2PDF as a Symfony Service

28665.3k](/packages/ensepar-html2pdf-bundle)[padam87/rasterize-bundle

HTML to PDF Symfony bundle. Works with Puppeteer, PhantomJS, and more.

1578.7k](/packages/padam87-rasterize-bundle)[jgrygierek/batch-entity-import-bundle

Importing entities with preview and edit features for Symfony.

101.0M1](/packages/jgrygierek-batch-entity-import-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
