2017 © Pedro Peláez
 

symfony-bundle pdf-report-bundle

Symfony Bundle. Wrapper of wkhtmltopdf that uses twig templating to generate pdf files.

image

discustecnologia/pdf-report-bundle

Symfony Bundle. Wrapper of wkhtmltopdf that uses twig templating to generate pdf files.

  • Tuesday, May 23, 2017
  • by rodrigoramosrx2
  • Repository
  • 0 Watchers
  • 1 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

pdf-report-bundle

logo Discus Tecnologia, (*1)

Symfony Bundle. Wrapper of wkhtmltopdf that uses twig templating to generate pdf files., (*2)


Dependencies

You need of wkhtmltopdf installed in your system., (*3)

Instalation

You need of the wkhtmltopdf installed in your OS., (*4)

Require the bundle with composer:, (*5)

composer require discustecnologia/pdf-report-bundle

Enable the bundle in the kernel:, (*6)

public function registerBundles()
{
    $bundles = [
        // ...
        new DiscusTecnologia\PdfReportBundle\DiscusTecnologiaPdfReportBundle(),
        // ...
    ];
    ...
}

How to use

In controllers instead of use:, (*7)

return $this->render(...);

You should use:, (*8)

$pdfReport = $this->get('discus-tecnologia.pdf-report');

$pdfReport->setHeader('default/header.twig');
$pdfReport->setFooter('default/footer.twig');
$pdfReport->setMargins(20, 20, 20, 20);
$pdfReport->addPages('default/testReport.twig', []);

return $pdfReport->generate();

Example of twig report based on records which shows 4 records per page:, (*9)

{% for i in ((pdfReportPageNumber -1) * 4)..(((pdfReportPageNumber * 4)-1) < (obj|length - 1) ? ((pdfReportPageNumber * 4)-1) : obj|length-1) %}


{{ obj[i] }}
{% endfor %}

Example Symfony Controller

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use DiscusTecnologia\PdfReportBundle\Service\PdfReport;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request)
    {
        $pdfReport = $this->get('discus-tecnologia.pdf-report');

        $pdfReport->setSavePDF("/var/tmp/pdfreport.pdf");
        $pdfReport->setHeader('default/header.twig');
        $pdfReport->setFooter('default/footer.twig');
        $pdfReport->setMargins(20, 20, 20, 20);
        //Default size is A4. You can use A0, A1, A2, A3, A4, A5 or pass custom size array as [width, height]
        $pdfReport->setPageSize(PdfReport::A3);
        $pdfReport->setGrayscale(true);
        $pdfReport->setOrientationLandscape();
        $pdfReport->setTotalPages(2);
        $pdfReport->setHeaderHeight(40);
        $pdfReport->setFooterHeight(40);
        $pdfReport->setCss("#footer p {
            font-size: 10px;
            text-align: center;
            background: #ccc;
        }

        #content {
            width:      168mm;
            /*border: 1px #000000 solid;*/
        }

        p {
            /*border: 1px #FF0000 solid;*/
            max-width:      168mm;
            text-indent: 30px;
            margin-bottom: 15px;
            line-height: 20px;
            font-size: 14px;
            text-align: justify;
        }");
        $pdfReport->addPages('default/testeRel.twig', ['obj' => ['a', 'b', 'c', 'd', 'e', 'f', 'g'] ]);
        return $pdfReport->generate();
        //return $pdfReport->renderHTML(); //use for debug
    }
}

Licence

This bundle is under the MIT license. See the complete license in the bundle., (*10)

Credits

Author: Rodrigo Ramos, (*11)

Discus Tecnologia, (*12)

The Versions

23/05 2017

dev-master

9999999-dev

Symfony Bundle. Wrapper of wkhtmltopdf that uses twig templating to generate pdf files.

  Sources   Download

MIT

The Requires

 

bundle symfony pdf report

22/05 2017

1.0.1

1.0.1.0

Symfony Bundle. Wrapper of wkhtmltopdf that uses twig templating to generate pdf files.

  Sources   Download

MIT

The Requires

 

bundle symfony pdf report

18/05 2017

1.0.0

1.0.0.0

Symfony Bundle. Wrapper of wkhtmltopdf that uses twig templating to generate pdf files.

  Sources   Download

MIT

The Requires

 

bundle symfony pdf report