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

2

3

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?

Septima answered 17/1, 2013 at 20:2 Comment(1)
I have the same problem but then when I e-mail it gives that error. I think the problem is in the pdf reader.Dative
B
0

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

Bergwall answered 7/5, 2013 at 10:10 Comment(0)
F
0

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

Flam answered 22/7, 2014 at 21:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.