【问题标题】:zend_pdf document issue in windows 7windows 7中的zend_pdf文档问题
【发布时间】:2012-09-05 10:49:21
【问题描述】:

我正在使用 zend_pdf 在 magento 1.7 中生成 pdf,我尝试过类似的方法

public function getpdf()
 {
 $pdf = new Zend_Pdf(); 
 $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
 $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
 $page->setFont($font, 24) ->drawText('Hello World', 72, 720);
 $pdf->pages[] = $page;
 $pdfString = $pdf->render();
header("Content-Disposition: attachment; filename=helloworld.pdf");
header("Content-type: application/x-pdf");
echo $pdfString;
 }

现在的问题是在 Windows 7 上生成 Pdf 时,它无法打开并抛出错误消息“Adobe reader 无法打开 helloworld.pdf,因为它不是受支持的文件类型或文件已损坏”。我注意到由于 pdf 文档中存在 html 内容而发生此错误。我将 pdf 文档作为链接https://dl.dropbox.com/u/45895040/helloworld.pdf 发送给您。

如果 pdf 是在 Mac OS X 中生成的,它会在那里成功打开

为了更好地理解,请尝试按照Zend_pdf document throws error in magento due to presence of html contents 中提到的步骤进行操作。

谁能指导我如何正确设置标题,以便生成的 pdf 可以在任何浏览器上打开,而与任何操作系统无关。

【问题讨论】:

    标签: php zend-framework magento-1.7 zend-pdf


    【解决方案1】:

    在 echo 语句之前添加以下代码行:

            ob_end_clean();
    

    这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-02
      相关资源
      最近更新 更多