使用zend_PDF打开Pdf文档时出现错误消息

时间:2012-08-22 12:46:43

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

我正在尝试使用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,因为它既不是受支持的文件类型,也不是因为文件已损坏............ 能帮助我解决这个问题!!!

1 个答案:

答案 0 :(得分:0)

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

所以,在该行之后添加:

$pdf->save('myfile.pdf');
相关问题