Adobe Reader cannot open .pdf file created using mPDF in Zend Framework

房东的猫 提交于 2019-12-12 16:04:20

问题


I'm trying to generate a .pdf file using mPDF in a Zend Framework application, from the output of the action.

Here is the code of my action:

public function testAction()
{       
        $this->_helper->viewRenderer->setNoRender();
        $this->_helper->layout->disableLayout();

        $this->view->foo = 'bar';

        $this->render();
        $output = $this->getResponse()->getBody();

        $layout = new Zend_Layout();
        $layout->content = $output;     
        $layout->setLayoutPath(dirname(dirname(__FILE__)) . '/views/layouts/');
        $layout->setViewSuffix('tpl');
        $layout->setLayout('pdf');

        $html = $layout->render();

        $mpdf = new mPDF('utf-8', 'A4');
        $mpdf->WriteHTML($html);
        $mpdf->Output('report.pdf', 'D');
}

If the content to be displayed is long (i.e. a few paragraphs), when downloading the .pdf file, Adobe Reader throws the following error: Adobe Reader could not open 'report.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).

However, if I pass the same output to mpdf as a static variable, without using Zend Layout render, then the .pdf file opens without any errors. Also, Adobe Reader throws the issue if and only if the content is long (i.e. it works if there are only a couple of words).

Is there any limit I should be aware of?


回答1:


there should not be space at beginning and at the end of file so check these space,




回答2:


Adobe Reader is less forgiving than some othe PDF readers if the PDF file is corrupt. Open your PDF document in a text editor and check that the file starts with something like: %PDF-1.4 %âãÃÓ

Sometimes PHP error notices are found at the top of the file.

Source : mpdf forum IanBack's answer



来源:https://stackoverflow.com/questions/14387158/adobe-reader-cannot-open-pdf-file-created-using-mpdf-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!