94noni/html2pdf-bundle

Html2pdf for Symfony.

v1.1.1 2021-12-30 18:21 UTC

This package is auto-updated.

Last update: 2024-11-09 00:17:53 UTC


README

Fork of the original

Difference with latest v0.x is the support of Symfony v6+ and PHP v8+, tagged here as v1.

Used for personal projects to render some PDF.

History

Html2pdf for Symfony applications.

Please read FrDeamon/EnseparHtml2pdfBundle#37

How to install?

Use Composer to install it:

$ composer require 94noni/html2pdf-bundle

Enable it in your config/bundles.php file:

Noni\Html2pdfBundle\NoniHtml2pdfBundle::class => ['all' => true],

How to use?

In your code:

use Noni\Html2pdfBundle\Factory\Html2pdfFactory;

class MyClass
{
    private Html2pdfFactory $html2pdfFactory;

    public function __construct(Html2pdfFactory $html2pdfFactory)
    {
        $this->html2pdfFactory = $html2pdfFactory;
    }
}

You can pass every options you would pass to Html2pdf, for instance:

$html2pdfFactory = $this->html2pdfFactory->create('P', 'A4', 'en', true, 'UTF-8', [10, 15, 10, 15]);

If the previous arguments are not provided, the factory uses its own default values. You can configure those default values by adding the bundle configuration to your config file:

noni_html2pdf:
    orientation: 'P'
    format: 'A4'
    lang: 'en'
    unicode: true
    encoding: 'UTF-8'
    margin: [10, 15, 10, 15]

Read more on the library Html2pdf here.