ZF-10880: Zend_Pdf_Parser : Support pdf version error

Description

When I try to merge some pdf files in another one, i have an exception when the pdf file is an 1.5 version.


Cross-reference streams are not supported yet.
#0 D:\librairies\ZendFramework-1.11.0\library\Zend\Pdf\Parser.php(452): Zend_Pdf_Parser->_loadXRefTable('116') 
#1 D:\librairies\ZendFramework-1.11.0\library\Zend\Pdf.php(309): Zend_Pdf_Parser->__construct('%PDF-1.5?%?????...', Object(Zend_Pdf_ElementFactory_Proxy), false)
#2 D:\wwwssl\EliosV2\application\default\controllers\GridController.php(497): Zend_Pdf->__construct('%PDF-1.5?%?????...', NULL, false) 
#3 D:\librairies\ZendFramework-1.11.0\library\Zend\Controller\Action.php(513): GridController->mergePdfAction() 
#4 D:\librairies\ZendFramework-1.11.0\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('mergePdfAction') 
#5 D:\librairies\ZendFramework-1.11.0\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#6 D:\wwwssl\EliosV2\application\bootstrap.php(27): Zend_Controller_Front->dispatch() 

$mergePdfName = $path . '/' . md5 ( uniqid () . microtime () ) . '.pdf';
$pdfMerged = new Zend_Pdf (); // Initializing the merged PDF
foreach($files as $src_stream) {
        $src= new Zend_Pdf ( $src_stream, null, false );
        foreach ( $source->pages as $page ) {   
                $templatePage = clone $page;
                $pageMerge = new Zend_Pdf_Page ( $templatePage );
                $pdfMerged->pages [] = $pageMerge;
        }
}
$pdfMerged->save ( $mergePdfName );
 

ZendFramework supports only pdf versions between 1 and 1.4, then I suggest this change:


  $pdfVersionComment = $this->_stringParser->readComment();
        if (substr($pdfVersionComment, 0, 5) != '%PDF-') {
            require_once 'Zend/Pdf/Exception.php';
            throw new Zend_Pdf_Exception('File is not a PDF.');
        }

        $pdfVersion = substr($pdfVersionComment, 5);
        if (version_compare($pdfVersion, '0.9',  '<')  ||
            version_compare($pdfVersion, '1.61', '>=')
           ) {
            /**
             * @todo
             * To support PDF versions 1.5 (Acrobat 6) and PDF version 1.7 (Acrobat 7)
             * Stream compression filter must be implemented (for compressed object streams).
             * Cross reference streams must be implemented
             */
            require_once 'Zend/Pdf/Exception.php';
            throw new Zend_Pdf_Exception(sprintf('Unsupported PDF version. Zend_Pdf supports PDF  1.0-1.4. Current version - \'%f\'', $pdfVersion));
        }
        $this->_pdfVersion = $pdfVersion;

  $pdfVersionComment = $this->_stringParser->readComment();
        if (substr($pdfVersionComment, 0, 5) != '%PDF-') {
            require_once 'Zend/Pdf/Exception.php';
            throw new Zend_Pdf_Exception('File is not a PDF.');
        }

        $pdfVersion = substr($pdfVersionComment, 5);
        if (version_compare($pdfVersion, '0.9',  '<')  ||
            version_compare($pdfVersion, '1.5', '>=')
           ) {
            /**
             * @todo
             * To support PDF versions 1.5 (Acrobat 6) and PDF version 1.7 (Acrobat 7)
             * Stream compression filter must be implemented (for compressed object streams).
             * Cross reference streams must be implemented
             */
            require_once 'Zend/Pdf/Exception.php';
            throw new Zend_Pdf_Exception(sprintf('Unsupported PDF version. Zend_Pdf supports PDF  1.0-1.4. Current version - \'%f\'', $pdfVersion));
        }
        $this->_pdfVersion = $pdfVersion;

Comments

No comments to display