以下代码用于执行和呈现pdf文件,方法是单击main.phmtl文件中的超链接,但单击它时只刷新视图页面。
public function pdfAction(){
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$pdf = new Zend_Pdf();
$pdf->properties['Title'] = "TITLE";
$pdf->properties['Author'] = "AUTHOR";
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$width = $page->getWidth(); // A4 : 595
$height = $page->getHeight(); // A4 : 842
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
$page->setFont($font, 36);
$page->drawText('Hello world!', 72, 720, 'UTF-8');
$pdf->pages[] = $page;
$this->getResponse()->setHeader('Content-type', 'application/x-pdf', true);
$this->getResponse()->setHeader('Content-disposition', 'inline; filename=my-file.pdf', true);
$this->getResponse()->setBody($pdf->render());
echo $pdf->render();
}
在视图(main.phmtl)
中<?php $url = $this->url(array("controller" => "Controller", "action" => "pdf")); ?>
<a href="<?php echo $url; ?>">test</a>
所以当我点击.phmtl文件中的上述测试超链接时,请帮我下载一个pdf文件。