Issue Type: Bug Created: 2006-08-04T12:27:14.000+0000 Last Updated: 2007-07-05T14:43:17.000+0000 Status: Resolved Fix version(s): - 1.0.0 RC1 (28/May/07)
Reporter: Tony Brady (tbrady) Assignee: Willie Alberty (willie) Tags: - Zend_Pdf
Related issues: - ZF-13
I'm trying to use Zend_Pdf to add some text to an existing pdf but I'm getting the following error:
Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'PDF file syntax error. Offset - 0xED6. 'stream' must be followed by either cr-lf sequence or lf character only.' in /Users/tonybrady/PHP/ZendFramework-0.1.5/library/Zend/Pdf/StringParser.php:592 Stack trace: #0 /Users/tonybrady/PHP/ZendFramework-0.1.5/library/Zend/Pdf/Element/Reference.php(167): Zend_Pdf_StringParser->getObject('19', Object(Zend_Pdf_Element_Reference_Context)) #1 /Users/tonybrady/PHP/ZendFramework-0.1.5/library/Zend/Pdf/Element/Reference.php(128): Zend_Pdf_Element_Reference->_dereference() #2 /Users/tonybrady/PHP/ZendFramework-0.1.5/library/Zend/Pdf/Page.php(389): Zend_Pdf_Element_Reference->getType() #3 /Users/tonybrady/PHP/ZendFramework-0.1.5/library/Zend/Pdf/Page.php(419): Zend_Pdf_Page->flush() #4 /Users/tonybrady/PHP/ZendFramework-0.1.5/library/Zend/Pdf.php(385): Zend_Pdf_Page->render(Object(Zend_Pdf_ElementFactory)) #5 /Users/tonybrady/PHP/ZendFramework-0.1.5/library/Zend/Pdf.php(483): Zend_Pdf->_dumpPages() #6 /Users/tonybrady/PHP/Z in /Users/tonybrady/PHP/ZendFramework-0.1.5/library/Zend/Pdf/StringParser.php on line 592
I've stripped out all code which isn't contributing to the problem and can reproduce the error with the following code snippet:
$pdf = Zend_Pdf::load('crr0303.pdf'); $page = $pdf->pages; // only has one page // Create new font $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Apply font $page->setFont($font, 10); $pdf->save('new.pdf');
It's the call to save() that triggers the error but removing the setFont() call eliminates the error. I'm on a Mac (OS X 10.4.7) and given the reference to line endings in the exception message I wondered if this is a Mac specific problem?
Posted by Mike Bowie (mbowie) on 2006-09-05T16:10:40.000+0000
I found this same exception occurs if you try to modify a document which has PDF security applied to it.
The class doesn't mind opening and saving the file, but if you perform any actions which will modify it... well, it ends in the dump provided in the previous post.
Posted by Willie Alberty (willie) on 2006-09-05T16:44:47.000+0000
When a PDF document has security applied, its content streams are encrypted. Those encrypted streams are usually stored as raw binary data, which is likely tripping up the stream parser. Linking to ZF-13 which adds support for PDF security (encryption).
Posted by Bill Karwin (bkarwin) on 2006-11-13T15:26:52.000+0000
Changing fix version to 0.6.0.
Posted by Alexander Veremyev (alexander) on 2007-05-25T02:17:12.000+0000
It's not clear, if this is a Mac problem or document encryption support problem. Document example should be provided.
Posted by Alexander Veremyev (alexander) on 2007-05-25T02:18:16.000+0000
Document example should be provided.
Posted by Tony Brady (tbrady) on 2007-05-25T04:56:49.000+0000
This issue is fixed in 0.9.3 (possibly fixed earlier but I've only just tried it with 0.9.3). I tested it with the pdf that caused the original error and it works perfectly now.
Posted by Alexander Veremyev (alexander) on 2007-05-25T06:12:16.000+0000
Thanks for feedback!
It looks it was ZF-15 related issue.
Have you found an issue?
See the Overview section for more details.