Create new pages using Zend PDF issue in PHP

304 Views Asked by At

I have stored the content of the pdf in the db as a text. I would like to create pdf file with more pages using the content from the db. Here is my code so far:

    $pdf = new Zend_Pdf();
    foreach ($pdfLabels as $label){
        $pdf->pages[] = $label->getPdfContentFromDb();  // here i have the content from the db 
    }
    $finalContent = $pdf->render();

But I am facing a fatal error:

Fatal error: Uncaught Error: Call to a member function render() on string in.  ...zendframework1/library/Zend/Pdf.php:733

I am sure that my way of trying to create a new pdf page and insert some content is wrong, so would you please advice ?

I was also checking this post: How to generate new page in zend PDF in foreach loop , but not sure how should I include my content still.

Thank you

1

There are 1 best solutions below

0
Attila Naghi On

I found out the fix:

        $pdf = new Zend_Pdf();
        foreach ($pdfLabels as $label){
            $pdfContent = new Zend_Pdf($label-> getPdfContentFromDb());
            $pdf->pages[] = clone $pdfContent->pages[0];
        } 
        $finalContent = $pdf->render();

I hope it will help someone!