PHP code example of uga / twig2pdf-bundle

1. Go to this page and download the library: Download uga/twig2pdf-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

uga / twig2pdf-bundle example snippets


new UGA\Html2PDFBundle\UGAHtml2PDFBundle() , 

    protected $pdf2html  ; 

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

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

    $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');

    

namespace Acme\MyAppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    
    protected $entityManager  ; 
    protected $template  ; 
    protected $pdf2html  ; 

    public function __construct(
                \Doctrine\ORM\EntityManager $entityManager , 
                \Twig_Environment $template  , 
                \UGA\Html2PDFBundle\Factory\Html2pdfFactory $pdf2html 
            )
    {
        $this->entityManager    = $entityManager;
        $this->template         = $template ; 
        $this->pdf2html         = $pdf2html ; 
    }
    
    public function indexAction()
    {

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

    $html2pdf =  $this->pdf2html->getInstance() ;
    $html2pdf->WriteHTML($template);
    $html2pdf->Output('exemple.pdf');
    
        return $this->render('AcmeMyAppBundle:Default:index.html.twig');
    }
}


$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);