【问题标题】:Error message when opening Pdf document using zend_PDF使用 zend_PDF 打开 Pdf 文档时出现错误消息
【发布时间】:2012-08-22 21:56:00
【问题描述】:

我正在尝试在 magento 1.7 中使用 Zend_PDF 组件生成 PDF,并在我的自定义控制器中尝试了以下代码

 public function getPdf()
 {
 $pdf = new Zend_Pdf();
 $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
 $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
 $page->setFont($font, 24)
   ->drawText('That which we call a rose,', 72, 720);
 $pdf->pages[0] = $page;
   $pdfString = $pdf->render();
header("Content-Disposition: attachment; filename=myfile.pdf");
header("Content-type: application/x-pdf");
echo $pdfString;
   }

在 phtml 文件中调用此方法后。它成功地创建了 PDF 文档。但是当我尝试打开这个 PDF 文档时。它抛出错误说: Adobe reader 无法打开 myfile.pdf,因为它不是受支持的文件类型或文件已损坏............ 有谁能帮我解决这个问题!!!

【问题讨论】:

  • 日志文件有错误吗?您是否尝试过删除标题函数以查看是否生成了 PDF 或者它只是抛出了一些错误?
  • 删除标题功能后,它只是显示混合的字母数字字符,如下所示.......%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������� ������������������������������������������������������ ����������������w!1.......

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


【解决方案1】:

$pdfString = $pdf->render(); 之后,您需要保存此文件。

所以,在该行之后添加:

$pdf->save('myfile.pdf');

【讨论】:

  • 我试过 r $pdfString = $pdf->render();在 $pdf->save('myfile.pdf');.不幸的是它仍然抛出错误说:Adobe阅读器无法打开myfile.pdf,因为它不是受支持的文件类型或文件已损坏............
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-02
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 2016-12-29
  • 1970-01-01
相关资源
最近更新 更多