我正在尝试使用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,因为它既不是受支持的文件类型,也不是因为文件已损坏............ 能帮助我解决这个问题!!!
答案 0 :(得分:0)
在$pdfString = $pdf->render();
之后,您需要保存此文件。
所以,在该行之后添加:
$pdf->save('myfile.pdf');