Adobe Reader无法在Zend Framework中打开使用mPDF创建的.pdf文件 [英] Adobe Reader cannot open .pdf file created using mPDF in Zend Framework

查看:147
本文介绍了Adobe Reader无法在Zend Framework中打开使用mPDF创建的.pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从动作的输出中在Zend Framework应用程序中使用mPDF生成.pdf文件.

I'm trying to generate a .pdf file using mPDF in a Zend Framework application, from the output of the 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');
}

如果要显示的内容很长(即几段),则在下载.pdf文件时,Adobe Reader会引发以下错误:Adobe Reader无法打开"report.pdf",因为它既不是受支持的文件键入或由于文件已损坏(例如,它作为电子邮件附件发送且未正确解码).

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).

但是,如果我在不使用Zend Layout渲染的情况下将相同的输出作为静态变量传递给mpdf,则.pdf文件将打开而不会出现任何错误.另外,仅当内容很长时(例如,只有几个单词时,Adobe Reader才起作用),Adobe Reader也会引发该问题.

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).

我应该注意什么限制?

推荐答案

如果PDF文件已损坏,则Adobe Reader的容忍度要低于其他PDF阅读器.在文本编辑器中打开PDF文档,并检查文件是否以类似以下内容开头: %PDF-1.4 %ââ£ÃÃ

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 %âãÃÃ"

有时,PHP错误通知位于文件顶部.

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

来源: mpdf论坛IanBack的回答

这篇关于Adobe Reader无法在Zend Framework中打开使用mPDF创建的.pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆