ZF2 How to save the pdf rendered by pdfModel?

i need some help plz , how can i save the pdf rendered by PdfModel, here is the code i use for generating the pdf ( the action/controller function ) :

public function genererPdfAction()
    {
        $id = (int) $this->params('id', null);


        $pdf = new PdfModel();
        $pdf->setOption("paperSize", "a4"); //Defaults to 8x11

        $pdf->setVariables(array(
          'produit' => $id
        ));

        return $pdf;
    }

Thanks.

Answers


here is the way i resolved the problem :

 public function generatePdfAction( $id = null){
$product = $id;
     $pdf = new PdfModel();
            $pdf->setOption("paperSize", "a4"); //Defaults to 8x11
     $pdfView = new ViewModel($pdf);
                $pdfView->setTerminal(true)
                    ->setTemplate('application/object/generate-pdf.phtml')
                    ->setVariables(array(
                       'produit' => $commande->getFkCategorie()->getDesignation(),
                      'product'=> $product
                    ));
                $html = $this->getServiceLocator()->get('viewpdfrenderer')->getHtmlRenderer()->render($pdfView);
                $eng = $this->getServiceLocator()->get('viewpdfrenderer')->getEngine();

                $eng->load_html($html);
                $eng->render();
                $pdfCode = $eng->output();
                file_put_contents('public/files/tmp-'.$id.'.pdf', $pdfCode);
    }

Hope it helps.


Need Your Help

Why is my stored procedure returning 0?

sql-server tsql stored-procedures

I am trying to get the sum of the pointsEarned column and the sum of the pointsPossible column. I want to turn this into a percentage. My problem is that my SP always returns 0, even when there are...

Checking if a nested dictionary key exists in VBA

excel vba data-structures dictionary

I am trying to use a dictionary of dictionaries in Excel VBA. What I'm trying to find out is whether the nested dictionary has a key already, and if not, add it.