Skip to content

[Maintenance][DX] Add support for PDF generation abstraction#426

Open
NoResponseMate wants to merge 1 commit intoSylius:2.2from
NoResponseMate:pdf/abstraction
Open

[Maintenance][DX] Add support for PDF generation abstraction#426
NoResponseMate wants to merge 1 commit intoSylius:2.2from
NoResponseMate:pdf/abstraction

Conversation

@NoResponseMate
Copy link
Copy Markdown
Contributor

@NoResponseMate NoResponseMate commented Mar 26, 2026

Summary

This PR adds support for sylius/pdf-generation-bundle as a modern alternative to the legacy PDF generation setup based on KnpSnappyBundle with a hardcoded wkhtmltopdf binary.

The new integration is opt-in and fully backward compatible — existing setups continue to work without any changes.

Motivation

The current PDF generation in InvoicingPlugin is tightly coupled to KnpSnappyBundle and wkhtmltopdf. The sylius/pdf-generation-bundle provides a proper abstraction layer with support for multiple adapters, context-based configuration, and a unified filesystem management — making it easier to swap PDF engines or customize the generation pipeline.

How to use it

To switch from the legacy PDF generation to the new bundle, set the legacy option to false in your configuration:

sylius_invoicing:
    pdf_generator:
        legacy: false

That's it. The plugin automatically configures a sylius_invoicing context in sylius/pdf-generation-bundle with the knp_snappy adapter and gaufrette storage, making it a drop-in replacement.

For more details on available adapters, storage options, and custom option processors, refer to the sylius/pdf-generation-bundle documentation.

Deprecations

The following classes, interfaces, and services have been deprecated and will be removed in 3.0:

Deprecated Replacement
Sylius\InvoicingPlugin\Generator\TwigToPdfGeneratorInterface Sylius\PdfGenerationBundle\Core\Renderer\TwigToPdfRendererInterface from sylius/pdf-generation-bundle
Sylius\InvoicingPlugin\Generator\TwigToPdfGenerator Sylius\PdfGenerationBundle\Core\Renderer\TwigToPdfRendererInterface from sylius/pdf-generation-bundle
Sylius\InvoicingPlugin\Generator\PdfOptionsGeneratorInterface Option processors from sylius/pdf-generation-bundle
Sylius\InvoicingPlugin\Generator\PdfOptionsGenerator Option processors from sylius/pdf-generation-bundle
Sylius\InvoicingPlugin\Manager\InvoiceFileManagerInterface Sylius\PdfGenerationBundle\Core\Filesystem\Manager\PdfFileManagerInterface from sylius/pdf-generation-bundle
Sylius\InvoicingPlugin\Manager\InvoiceFileManager Sylius\PdfGenerationBundle\Core\Filesystem\Manager\PdfFileManager from sylius/pdf-generation-bundle

The corresponding services (sylius_invoicing.generator.twig_to_pdf, sylius_invoicing.generator.pdf_options) are also deprecated.

The following services now accept new argument types from the SyliusPdfGenerationBundle. Passing the old types is deprecated and will be removed in 3.0:

  • Sylius\InvoicingPlugin\Generator\InvoicePdfFileGenerator:

    public function __construct(
    -   private readonly TwigToPdfGeneratorInterface $twigToPdfGenerator,
    +   private readonly TwigToPdfGeneratorInterface|TwigToPdfRendererInterface $twigToPdfRenderer,
        private readonly FileLocatorInterface $fileLocator,
        private readonly InvoiceFileNameGeneratorInterface $invoiceFileNameGenerator,
        private readonly string $template,
        private readonly string $invoiceLogoPath,
    )
  • Sylius\InvoicingPlugin\Creator\InvoiceCreator:

    public function __construct(
        private readonly InvoiceRepositoryInterface $invoiceRepository,
        private readonly OrderRepositoryInterface $orderRepository,
        private readonly InvoiceGeneratorInterface $invoiceGenerator,
        private readonly InvoicePdfFileGeneratorInterface $invoicePdfFileGenerator,
    -   private readonly InvoiceFileManagerInterface $invoiceFileManager,
    +   private readonly InvoiceFileManagerInterface|PdfFileManagerInterface $invoiceFileManager,
        private readonly bool $hasEnabledPdfFileGenerator = true,
    )
  • Sylius\InvoicingPlugin\Provider\InvoiceFileProvider — the $invoiceFileManager and $invoicesDirectory arguments are also deprecated and will be removed in 3.0:

    public function __construct(
        private readonly InvoiceFileNameGeneratorInterface $invoiceFileNameGenerator,
    -   private readonly FilesystemInterface $filesystem,
    +   private readonly FilesystemInterface|PdfFileManagerInterface $filesystem,
        private readonly InvoicePdfFileGeneratorInterface $invoicePdfFileGenerator,
    -   private readonly InvoiceFileManagerInterface $invoiceFileManager,
    -   private readonly string $invoicesDirectory,
    +   private readonly ?InvoiceFileManagerInterface $invoiceFileManager = null,
    +   private readonly ?string $invoicesDirectory = null,
    )

Issues

Fixes #376

@NoResponseMate NoResponseMate changed the base branch from 2.1 to 2.2 March 26, 2026 15:24
@GSadee GSadee marked this pull request as ready for review April 16, 2026 12:40
@GSadee GSadee added Feature New feature proposals. Maintenance Configurations, READMEs, releases, etc. DX Issues and PRs aimed at improving Developer eXperience. labels Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DX Issues and PRs aimed at improving Developer eXperience. Feature New feature proposals. Maintenance Configurations, READMEs, releases, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants