I have created function getPdf in my custom controller
public function getPdf()
{
$pdf = new Zend_Pdf();
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$imagePath="C:\Users\Hp\Desktop\landscape3.jpg";
$image = Zend_Pdf_Image::imageWithPath($imagePath);
$page->drawImage($image, 40,764,240, 820);
$pdf->pages[] = $page;
$pdf->save('myfile.pdf');
}
It generates PDF with image but in magento1.7 folder. I have tried the following lines
$pdfString = $pdf->render();
header("Content-Disposition: attachment; filename=mydownloads.pdf");
header("Content-type: application/x-pdf");
echo $pdfString;
It generates PDF document in Downloads folder but when I open it.An error message is displayed:Adobe reader couldn't open myfile.pdf because it's not either a supported file type or because the file has been damaged............ When I open mydownloads.pdf in text editor (notepad), I notice presence of html contents(the contents of current phtml file in which getPdf() function is called) with pdf's own contents.I even tried to disable view rendering in magento1.7 by using
$vr = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$vr->setNoRender(true);
$layout = Zend_Layout::getMvcInstance();
$layout->disableLayout();
but unfortunately it didn't work in magento1.7.Then I tried to echo the contents of $pdfString by removing those two lines of header function
like
$pdfString = $pdf->render();
return $pdfString;
It simply contained Pdf's own contents. Then I realised that presence of html contents is due to these two lines
header("Content-Disposition: attachment; filename=mydownloads.pdf");
header("Content-type: application/x-pdf");
Can anybody help me in resolving this issue. So that PDF document is generated in download folder. How to remove html contents from pdf document?