render HTML as PDF page using TCPDF library
PHP
Pull request Compare This branch is 1 commit ahead of ioalessio:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DependencyInjection
Helper
Resources/config
IoTcpdfBundle.php
README.md

README.md

How to Install

  1. First download TCPDF library and put it in the vendor folder.

  2. Add this bundle to your vendor/ dir. Add the following lines in your deps file.

    [IoTcpdfBundle]
        git=git://github.com/tvlooy/IoTcpdfBundle.git
        target=/bundles/Io/TcpdfBundle

Run the vendor script:

    ./bin/vendors install
  1. Add the "Io" namespace to your autoloader:
    // app/autoload.php

    $loader->registerNamespaces(array(
        'Io' => __DIR__.'/../vendor/bundles',
        // your other namespaces
    ));

    // In same file include tcpdf library

    require_once __DIR__.'/../vendor/tcpdf/tcpdf.php';
  1. Add the "Io" namespace to your kernel:
    // app/ApplicationKernel.php

    public function registerBundles()
    {
        return array(
            // ...
            new Io\TcpdfBundle\IoTcpdfBundle(),
            // ...
        );
    }

HOW TO USE:

// MyBundle/Controllers/MyController.php

class MyController extends Controller
{
    /**
     * @Route("/mypage.pdf")
     */
    public function myPageAction()
    {
        $html = $this->renderView('MyBundle:MyController:myPage.pdf.twig', array());

        // io_tcpdf will return a Response object
        return $this->get('io_tcpdf')->generate($html);
    }
}
// MyBundle/Resources/views/MyController/myPage.pdf.twig
put here your html code

TODO

  • smart method for easier PDF generation and customization
  • cache pdf generation
  • @PDF('template.twig') annotation system