2017 © Pedro Peláez
 

library lospdf

ZF2 module to wrapper some pdf generation libraries

image

los/lospdf

ZF2 module to wrapper some pdf generation libraries

  • Saturday, April 23, 2016
  • by Lansoweb
  • Repository
  • 2 Watchers
  • 1 Stars
  • 3,698 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 7 Versions
  • 6 % Grown

The README.md

LosPdf

Latest Stable Version Total Downloads Scrutinizer Code Quality SensioLabs Insight Dependency Status, (*1)

Introduction

This ZF2 module provides a wrapper to mPdf (more coming) to generate PDF documents from html., (*2)

Requirements

Instalation

Instalation can be done with composer ou manually, (*3)

Installation with composer

For composer documentation, please refer to getcomposer.org., (*4)

  1. Enter your project directory
  2. Create or edit your composer.json file with following contents:, (*5)

    json { "require": { "los/lospdf": "1.*", "mpdf/mpdf" : ">=v5.7.4", } }, (*6)

  3. Run php composer.phar install
  4. Open my/project/directory/config/application.config.php and add LosPdf to your modules, (*7)

    <?php
    return array(
        'modules' => array(
            'LosPdf',
            'Application'
        ),
        'module_listener_options' => array(
            'config_glob_paths'    => array(
                'config/autoload/{,*.}{global,local}.php',
            ),
            'module_paths' => array(
                './module',
                './vendor',
            ),
        ),
    );
    

Installation without composer

  1. Clone this module LosPdf to your vendor directory
  2. Enable it in your config/application.config.php like the step 4 in the previous section.

Usage

Render to browser

The following example demonstrates a typical usage of the LosPdf module inside an Action in a Controller:, (*8)

    public function pdfAction()
    {
        $generated = new \DateTime('now');
        $genetared = $gerado->format('d/m/Y H:i:s');

        $pdf = new PdfModel();
        $renderer = $this->getServiceLocator()->get('ViewPdfRenderer');
        $renderer->getEngine()->setHTMLHeader('<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic; border-bottom: 1px solid #000"><tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">Client</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">Report Name</td>
<td width="33%" style="text-align: right; ">My Company</td>
</tr></table>
');
        $renderer->getEngine()->setHTMLFooter('Footer', '

Generated: '.$generated.' Page {PAGENO}
'); $pdf->setTerminal(true); $pdf->setVariables(['name'=>'Leandro']); $pdf->setOption("paperSize", "a4"); return $pdf; }

And use the view file as usual., (*9)

You can set any mPdf option through $renderer->getEngine():, (*10)

$renderer = $this->getServiceLocator()->get('ViewPdfRenderer');
$renderer->getEngine()->pagenumPrefix = 'Page n ';

Render to string

You can capture the pdf output to a string:, (*11)

    public function pdfAction()
    {
        $generated = new \DateTime('now');
        $genetared = $gerado->format('d/m/Y H:i:s');

        $pdf = new PdfModel();
        $renderer = $this->getServiceLocator()->get('ViewPdfRenderer');
        $renderer->getEngine()->setHTMLHeader('<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic; border-bottom: 1px solid #000"><tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">Client</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">Report Name</td>
<td width="33%" style="text-align: right; ">My Company</td>
</tr></table>
');
        $renderer->getEngine()->setHTMLFooter('Footer', '

Generated: '.$generated.' Page {PAGENO}
'); $pdf->setTerminal(true); $pdf->setVariables(['name'=>'Leandro']); $pdf->setOption("paperSize", "a4"); $pdf->setTemplate('site/index/pdf'); $output = $renderer->renderToString($pdf); //Do something with output }

Render to file

You can save the pdf to a file:, (*12)

    public function pdfAction()
    {
        $generated = new \DateTime('now');
        $genetared = $gerado->format('d/m/Y H:i:s');

        $pdf = new PdfModel();
        $renderer = $this->getServiceLocator()->get('ViewPdfRenderer');
        $renderer->getEngine()->setHTMLHeader('<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic; border-bottom: 1px solid #000"><tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">Client</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">Report Name</td>
<td width="33%" style="text-align: right; ">My Company</td>
</tr></table>
');
        $renderer->getEngine()->setHTMLFooter('Footer', '

Generated: '.$generated.' Page {PAGENO}
'); $pdf->setTerminal(true); $pdf->setVariables(['name'=>'Leandro']); $pdf->setOption("paperSize", "a4"); $pdf->setTemplate('site/index/pdf'); $renderer->renderToFile($pdf, '/tmp/report.pdf'); }

Mixing outputs

You can use more than one render type. the following example will save the pdf to a file, render the pdf to a string and to the browser:, (*13)

    public function pdfAction()
    {
        $generated = new \DateTime('now');
        $genetared = $gerado->format('d/m/Y H:i:s');

        $pdf = new PdfModel();
        $renderer = $this->getServiceLocator()->get('ViewPdfRenderer');
        $renderer->getEngine()->setHTMLHeader('<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic; border-bottom: 1px solid #000"><tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">Client</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">Report Name</td>
<td width="33%" style="text-align: right; ">My Company</td>
</tr></table>
');
        $renderer->getEngine()->setHTMLFooter('Footer', '

Generated: '.$generated.' Page {PAGENO}
'); $pdf->setTerminal(true); $pdf->setVariables(['name'=>'Leandro']); $pdf->setOption("paperSize", "a4"); $pdf->setTemplate('site/index/pdf'); $output = $renderer->renderToString($pdf); $renderer->renderToFile($pdf, '/tmp/report.pdf'); return $pdf; }

The Versions

23/04 2016

dev-master

9999999-dev

ZF2 module to wrapper some pdf generation libraries

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 pdf mpdf los

23/04 2016

1.0.1

1.0.1.0

ZF2 module to wrapper some pdf generation libraries

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 pdf mpdf los

23/05 2015

1.0.0

1.0.0.0

ZF2 module to wrapper some pdf generation libraries

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 pdf mpdf los

01/04 2015

0.9.4

0.9.4.0

ZF2 module to wrapper some pdf generation libraries

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 pdf mpdf los

25/03 2015

0.9.3

0.9.3.0

ZF2 module to wrapper some pdf generation libraries

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 pdf mpdf los

26/02 2015

0.9.2

0.9.2.0

ZF2 module to wrapper some pdf generation libraries

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 pdf mpdf los

23/02 2015

0.9.1

0.9.1.0

ZF2 module to wrapper some pdf generation libraries

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 pdf mpdf los