PHPackages                             uga/twig2pdf-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. uga/twig2pdf-bundle

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

uga/twig2pdf-bundle
===================

twig2pdf

v1.3(9y ago)2272.5k5[1 issues](https://github.com/nfouka/HTML2PDF_spipu/issues)MITPHPPHP &gt;=5.5

Since Feb 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/nfouka/HTML2PDF_spipu)[ Packagist](https://packagist.org/packages/uga/twig2pdf-bundle)[ Docs](https://github.com/nfouka)[ RSS](/packages/uga-twig2pdf-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Twig2PDF\_SPIPU LIB for Symfony 2.8 / 3.x
=========================================

[](#twig2pdf_spipu-lib-for-symfony-28--3x)

[![](https://github.com/nfouka/HTML2PDF_spipu/raw/master/logo.png?raw=true)](https://github.com/nfouka/HTML2PDF_spipu/blob/master/logo.png?raw=true)

Twig2pdf Bundle
===============

[](#twig2pdf-bundle)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/910054ab7c1a7ca4a023732dfcdd6b4c40dbe5912519f9ec73894c91c75eed81/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e666f756b612f48544d4c325044465f73706970752f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nfouka/HTML2PDF_spipu/?branch=master)[![Minimum PHP Version](https://camo.githubusercontent.com/dd6bad85ee03cf570f4cf82ab69a80396fdbf48050af932f8f23aa551b0d1e5a/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e352d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/4b947a6ce62201ea7462dad78c36730d1cc5c7c4e920e2a78cddd1157659ee56/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f676f616f702f676f616f702d73796d666f6e792d62756e646c652e737667)](https://packagist.org/packages/goaop/goaop-symfony-bundle)[![Build Status](https://camo.githubusercontent.com/b6e82bebd47927b8a8c1393fb562bd236c1f42846b82963ec0b2c1d945cc9654/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e666f756b612f48544d4c325044465f73706970752f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nfouka/HTML2PDF_spipu/build-status/master)

Twig2pdf for Symfony 2/Drupal 8 as a service.

```
 _______        _____ ____ _  _   ____  ____  _____
|_   _\ \      / /_ _/ ___| || | |  _ \|  _ \|  ___|
  | |  \ \ /\ / / | | |  _| || |_| |_) | | | | |_
  | |   \ V  V /  | | |_| |__   _|  __/| |_| |  _|
  |_|    \_/\_/  |___\____|  |_| |_|   |____/|_|

 ____  _   _ _   _ ____  _     _____   ______   __
| __ )| | | | \ | |  _ \| |   | ____| | __ ) \ / /
|  _ \| | | |  \| | | | | |   |  _|   |  _ \\ V /
| |_) | |_| | |\  | |_| | |___| |___  | |_) || |
|____/ \___/|_| \_|____/|_____|_____| |____/ |_|

 ____  _        _    _   _ _____ _____ ____  ____  _______     __
|  _ \| |      / \  | \ | | ____|_   _/ __ \|  _ \| ____\ \   / /
| |_) | |     / _ \ |  \| |  _|   | |/ / _` | | | |  _|  \ \ / /
|  __/| |___ / ___ \| |\  | |___  | | | (_| | |_| | |___  \ V /
|_|   |_____/_/   \_\_| \_|_____| |_|\ \__,_|____/|_____|  \_/
                                      \____/

```

How to install ?
----------------

[](#how-to-install-)

Just add this to your composer.json file:

```
"require": {
  "uga/twig2pdf-bundle": "^1.1"
}

Or you tape in your ROOT project
composer require uga/twig2pdf-bundle
```

Enable it in the Kernel

```
new UGA\Html2PDFBundle\UGAHtml2PDFBundle() ,
```

How to make it ?
----------------

[](#how-to-make-it--)

In your controller:

```
    protected $pdf2html  ;

    public function __construct(
                \UGA\Html2PDFBundle\Factory\Html2pdfFactory $pdf2html
            )
    {
        $this->pdf2html         = $pdf2html ;
    }
```

In your action:

```
    $html2pdf =  $this->pdf2html->getInstance() ;
    $html2pdf->WriteHTML($template);
    $html2pdf->Output('exemple.pdf');
```

You can pass every option you would pass to twig2pdf, for instance :

```
$html2pdf = $this->pdf2html->getInstance('P', 'A4', 'en', true, 'UTF-8', array(10, 15, 10, 15)); or by container
$html2pdf =  $this->container->get('uga_html2_pdf.service')->getInstance('P', 'A4', 'fr', null, null, null);

```

If the previous arguments are not provided, the factory uses its own default values. You can change this default values by adding the bundle configuration to your `app/config/config.yml` :

```
uga_html2_pdf:
    html2_pdf_orientation: 'P'
    html2_pdf_format: 'A4'
    html2_pdf_lang: 'fr'
    html2_pdf_unicode: true
    html2_pdf_encoding: 'UTF-8'
    html2_pdf_margin: [10,15,10,15]
```

Integration with twig template :

```
    $template = $this->template->render('AcmeMyAppBundle:Default:index.html.twig',array(
        'CLASS_HTML2PDF' => "HTML2PDF FOR SYMFONY 2.8.18 "
    )) ;

    $html2pdf =  $this->pdf2html->getInstance() ;
    $html2pdf->WriteHTML($template);
    $html2pdf->Output('exemple.pdf');
```

Full example ( Controller ) :

```
