Question

I am trying to generate PDF using Zend_PDF component in magento 1.7 and have tried the following code in my custom controller

 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;
   }

After calling this method in phtml file. It successfully creates PDF document. But when I try to open this PDF document. It throws error saying : Adobe reader couldn't open myfile.pdf because it's not either a supported file type or because the file has been damaged............ Can any help me in resolving this issue!!!

Was it helpful?

Solution

After $pdfString = $pdf->render();, you will need to save this file.

So, add this after that line:

$pdf->save('myfile.pdf');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top