This below code to execute and render pdf file from clicking a hyperlink in main.phmtl file but when clicking it just refreshes the view page.
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();
}
In the view (main.phmtl)
<?php $url = $this->url(array("controller" => "Controller", "action" => "pdf")); ?>
<a href="<?php echo $url; ?>">test</a>
So please help me to download a pdf file when I click the above Test hyperlink in the .phmtl file.