Magento 1.9 PDF – Simple Zend PDF File Not Generating

magento-1.9pdfzend-framework

I tried below simple code in my TestController.php code but not generate pdf file. When I call testAction method of TestController.php it displays blank on page and no error on page and as well as not generate pdf file

class Namespace1_Module1_TestController extends Mage_Core_Controller_Front_Action
{ 
  public function testAction()
  { 
  pdf = new Zend_Pdf();
    $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    //var_dump($page);
    $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

    define('FONT_SIZE'      , 12);
    define('MARGIN_LEFT'    , 40);
    define('MARGIN_TOP'     , 40);
    define('COL_WIDTH'      , 100);
    define('COL_LEFT_MARGIN', 10);
    define('COL_SEPARATOR'  , '|');
    define('ROW_HEIGHT'     , 20);

    $row = 1;
    $x = MARGIN_LEFT;
    $y = MARGIN_TOP;

    $page->setFont($font, FONT_SIZE);

                $page->drawText('ABCD', $x, $page->getHeight() - $y);
                $x += COL_WIDTH;
                $x += COL_LEFT_MARGIN;
                $x = MARGIN_LEFT;
                $y += ROW_HEIGHT;

    $pdf->pages[] = $page;
    $pdf->save('data.pdf', true);
  }
}

Where I Wrong to generate pdf file ?

Best Answer

You should add return value as this code below:

return $this->_prepareDownloadResponse ( 'test.pdf', $pdf->render (), 'application/pdf' );
Related Topic