If you try to open the file using a text editor (or a hex editor), what will you get?
Your PDF should contain only PDF data, not HTML or white space at the beginning or end.
, , Zend Framework.
- :
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
, -, , , , ...
- , , PDF ? - , :
$pdf->save(CACHE_DIR . '/test-pdf.pdf');
, , ; , PDF , , PDF .
, :
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();
$height = $page->getHeight();
$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());
}
, ; :
; !