Issues

ZF-11666: Zend_Pdf renders corrupt file after serialize-unserialize

Issue Type: Improvement Created: 2011-08-13T21:32:15.000+0000 Last Updated: 2012-03-10T00:44:07.000+0000 Status: Closed Fix version(s): Reporter: Bavo Janss (bavo) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Pdf

  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: Attachments:

Description

After serializing and unserializing a Zend_Pdf object with pages everything seems ok until you add additional pages to the object. Rendered PDF is corrupt, it contains unreadable text (font information missing?), blank pages appear and pages are repeated randomly.

sniplet to reproduce behauviour:

<pre class="highlight">
if (!isset($_SESSION['PDF'])) {

    $pdf = new Zend_Pdf();

    $pdf->pages[] = $objPage = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 16);
    $objPage->drawText('Page ' . count($pdf->pages), 100, 150);

    $pdf->pages[] = $objPage = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 16);
    $objPage->drawText('Page ' . count($pdf->pages), 100, 150);

    $_SESSION['PDF'] = serialize($pdf);
    echo 'object serialized';
} else {

    $pdf = unserialize($_SESSION['PDF']);

    $pdf->pages[] = $objPage = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 16);
    $objPage->drawText('Page ' . count($pdf->pages), 100, 150);

    $pdf->pages[] = $objPage = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 16);
    $objPage->drawText('Page ' . count($pdf->pages), 100, 150);

    header('Content-type: application/pdf');
    echo $pdf->render();

    unset($_SESSION['PDF']);
}

Comments

Posted by Pádraic Brady (padraic) on 2011-08-21T12:24:03.000+0000

Switching to major improvement type - an object not being serializable is not a bug. There's never any such guarantee. I would instead use a container object to port the necessary data around in sessions, and use that to repopulate a new Zend_Pdf object as needed.

Posted by Adam Lundrigan (adamlundrigan) on 2011-11-08T13:00:36.000+0000

@[~padraic]: Should this issue be marked as postponed to next major release, then?...or should this also be implemented in ZFv1?

Posted by Adam Lundrigan (adamlundrigan) on 2012-03-10T00:44:07.000+0000

Closing as Won't Fix for ZF1. [~padraic] has provided a workaround which should work for all cases.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts