SchoenefHtmlToPdfBundle
A simple bundle to add html 2 pdf service provider in a simple way to your symfony project. Currently it supports:, (*1)
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:, (*2)
$ composer require schoenef/html-to-pdf-bundle:~1.0
This command requires you to have Composer installed globally, as explained
in the installation chapter
of the Composer documentation., (*3)
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:, (*4)
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Schoenef\HtmlToPdfBundle\SchoenefHtmlToPdfBundle(), // takes care of html to pdf conversion via third party services
);
// ...
}
// ...
}
Add the following configuration to your app/config/config.yml
:, (*5)
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 app/config/parameter.yml
:, (*6)
parameters:
...
html_to_pdf_apikey: yourApiKey
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
To use the html to pdf connector and save pdf files, you can use the following inside of symfony controllers:, (*7)
$connector = $this->get('schoenef_html_to_pdf.connector');
$connector->saveUrlAsPdf('http://some.url', 'some/file/path.pdf', ['dpi' => 96]);