If you try to open the file with a text editor (or an hexadecimal editor), what do you get ?
Your PDF file must contain only PDF data, and not any HTML or blank space at the beginning or the end.
One thing that could cause troubles is the automatic rendering of a View by Zend Framework.
Using something like this at the beginning of your action might help :
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
I've looked at a sample I wrote sometime action, and it's the only difference I see with what you did, actually...
If it still doesn't work, what if you try saving the PDF to a file instead of sending it to the user ? With something like that, for instance :
$pdf->save(CACHE_DIR . '/test-pdf.pdf');
I know it's not what you want to do ; but it would allow you to check if the PDF is well-generated, to identify if the problem is with the PDF generation, or with it's output.
And here is the full example I was talking about :
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
$imagePath = WEB_DIR . '/images/logo.png';
$image = Zend_Pdf_Image::imageWithPath($imagePath);
$x = 15;
$y = $height - 15 - 106/2;
$page->drawImage($image, $x, $y, $x+155/2, $y+106/2);
$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());
}
As far as I remember, this was working fine a couple of months ago ; and the only differences with your code are :
- disabling the layout / rendering
- using a logo ; but that shouldn't do much of a difference
Hope this helps ; Have fun!