PHP code example of los / lospdf

1. Go to this page and download the library: Download los/lospdf 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/ */

    

los / lospdf example snippets


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

    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', '<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic; border-top: 1px solid #000"><tr>
<td width="50%" style="text-align: left; font-weight: bold; font-style: italic;">Generated: '.$generated.'</td>
<td width="50%" style="text-align: right; ">Page {PAGENO}</td>
</tr></table>
');

        $pdf->setTerminal(true);
        $pdf->setVariables(['name'=>'Leandro']);
        $pdf->setOption("paperSize", "a4");

        return $pdf;
    }

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

    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', '<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic; border-top: 1px solid #000"><tr>
<td width="50%" style="text-align: left; font-weight: bold; font-style: italic;">Generated: '.$generated.'</td>
<td width="50%" style="text-align: right; ">Page {PAGENO}</td>
</tr></table>
');

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

    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', '<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic; border-top: 1px solid #000"><tr>
<td width="50%" style="text-align: left; font-weight: bold; font-style: italic;">Generated: '.$generated.'</td>
<td width="50%" style="text-align: right; ">Page {PAGENO}</td>
</tr></table>
');

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

    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', '<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic; border-top: 1px solid #000"><tr>
<td width="50%" style="text-align: left; font-weight: bold; font-style: italic;">Generated: '.$generated.'</td>
<td width="50%" style="text-align: right; ">Page {PAGENO}</td>
</tr></table>
');

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