schoenef / html-to-pdf-bundle
A simple bundle to add html 2 pdf service provider in a simple way to your symfony project.
Installs: 51
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^6.0 | ^7.0
- symfony/framework-bundle: ^6.2
This package is auto-updated.
Last update: 2025-09-02 14:52:13 UTC
README
A simple bundle to add html 2 pdf service provider in a simple way to your symfony project. Currently, it supports:
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require schoenef/html-to-pdf-bundle:~2.0
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, if not happening automatically, enable the bundle by adding it to the list of registered bundles
in the cofig/bundles.php
file of your project:
<?php // cofig/bundles.php // ... return [ // ... Schoenef\HtmlToPdfBundle\SchoenefHtmlToPdfBundle::class => ['all' => true], // ... ]
Step 3: Configure the Bundle
Add the following configuration to your config/packages/schoenef_html_to_pdf.yaml
:
schoenef_html_to_pdf: provider: pdfrocket timeout: 20 apikey: "%html_to_pdf_apikey%" default_options: shrinking: false dpi: 300 image_quality: 100 page_size: A4 zoom: 1.2 js_delay: 500
And to your .env
:
HTML_TO_PDF_API_KEY=change_me
Available configuration options
- provider: default: pdfrocket - no other value available at the moment
- timeout: default: 20 - the timeout in seconds of a single http call
- apikey: The api key you got from your provider to turn html pages into pdf
- default_options: mapping of pdf options
- shrinking | (boolean) - if set to false, smart-shrinking is dissabled
- dpi | (integer) - allows to set the dpi
- image_quality | (integer) - allows to define the image quality
- page_size | (enum) - allows to define the pdf page size -
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 B0 B1 B1 B2 B3 B4 B5 B6 B7 B8 B9 C5E Comm10E DLE Executive Folio Ledger Legal Letter Tabloid
- zoom | (float) - a float number, to zoom the page
- js_delay | (integer) - render delay in milliseconds - good to allow the load of external fonts are ajax requests to finish
Usage
Inject the Service then in the __construct of cour controller or service.
<?php namespace App\Service; use Schoenef\HtmlToPdfBundle\Service\Html2PdfConnector; class MyService { public function __construct( private readonly Html2PdfConnector $html2PdfConnector, ) {} public function toPdf () { $this->html2PdfConnector->saveUrlAsPdf('http://some.url', 'some/file/path.pdf', ['dpi' => 96]); } }