ZF-4320: Moving a page between document fails with exception


using the following code: require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); echo "


pre>"; try { $pdf = Zend_Pdf::load("test/pages.pdf"); $pdfNew = new Zend_Pdf(); $page1 = new Zend_Pdf_Page($pdf->pages[0]); $pdfNew->pages[] = $page1; $pdfNew->save("ttt/p1.pdf"); echo "Done.".PHP_EOL; } catch (Exception $e) { echo $e; }

The following exception is received: exception 'Zend_Pdf_Exception' with message 'Page is attached to one documen, but rendered in context of another.' in /var/www/html/library/Zend/Pdf/Page.php:499 Stack trace:

0 /var/www/html/library/Zend/Pdf.php(474): Zend_Pdf_Page->render(Object(Zend_Pdf_ElementFactory_Proxy))

1 /var/www/html/library/Zend/Pdf.php(742): Zend_Pdf->_dumpPages()

2 /var/www/html/library/Zend/Pdf.php(260): Zend_Pdf->render(false, Resource id #263)

3 /var/www/html/index.php(13): Zend_Pdf->save('ttt/p1.pdf')

4 {main}


I've got the same problem here. If I want to merge some PDF files like:

$pdf = new Zend_Pdf(); ... $template = new Zend_Pdf("template.pdf", null, true); $pdf->pages[0] = new Zend_Pdf_Page($template->pages[0]);

$pdfPage = new Zend_Pdf_Page(); $pdf->pages[1] = $pdfPage;

is there any plan to implement this?

From the source code that throws that exception:

             * @todo Page cloning must be implemented here instead of exception.
             *       PDF objects (ex. fonts) can be shared between pages.
             *       Thus all referenced objects, which can be modified, must be cloned recursively,
             *       to avoid producing wrong object references in a context of source PDF.

I look into it if it can be implemented.

On first sight, this cannot be implemented in a fast way.

We are generating several reports from our database automaticaly with Zend PDF, but are not able to merge different reports into one PDF document or to move pages between documents. Would it be possible that one of the developers of Zend PDF could solve this? We would be gladly willing to give a donation to support zend framework in order to get this issue solved.