g v s vinayak
g v s vinayak

Reputation: 87

How to Create pdf with zend2 and dompdf

I want to use dompdf for generation pdf document. i got pdf response with follwing code by using DOMPDFModule.But my question is how can i pass variable to the phtml file in order to get print on pdf file my code is as follows

    use DOMPDFModule\View\Model\PdfModel;
    ...
    ..

    public function printAction()
   {
    $campaignsList=$this->getcampaignTable()->getCampaignList();
    $model = new PdfModel();
    $model->setOption('paperSize', 'a4');
    $model->setOption('paperOrientation', 'landscape');
    return $model;
    }    

How can i print that $campaignList array in print.phtml file

Thanks in advance

Upvotes: 2

Views: 3068

Answers (1)

Tom Metcalfe
Tom Metcalfe

Reputation: 308

I'm not 100% sure what you're asking, you can create the PDF entirely within your action without involving the view(presume this is what you meant when reference your phtml file).

Some example code on PDF generation with DOMpdf :

<?php
    // Create a new DOMPDF object
    $dompdf = new \DOMPDF();
    // Set the paper size to A4
    $dompdf->set_paper('A4');
    // Load the HTML
    $dompdf->load_html($html);
    // Render the PDF
    $dompdf->render();
    // Set the PDF Author
    $dompdf->add_info('Author', 'I am the Author');
    // Set the PDF Title
    $dompdf->add_info('Title', 'My PDF Title');

    /**
    * 'Attachment' => 1 or 0 - if 1, force the browser to open a
    * download dialog, on (1) by default
    */
    $dompdf->stream($name,array('Attachment'=>1));
?>

And the documented usage - DOMPDF LINK

Upvotes: 2

Related Questions