问题
I am using zend_pdf to generate pdf in magento 1.7 and I have tried something like
public function getpdf()
{
$pdf = new Zend_Pdf();
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$page->setFont($font, 24) ->drawText('Hello World', 72, 720);
$pdf->pages[] = $page;
$pdfString = $pdf->render();
header("Content-Disposition: attachment; filename=helloworld.pdf");
header("Content-type: application/x-pdf");
echo $pdfString;
}
Now the problem is when Pdf is generated on Windows 7, it doesn't open and throws error message saying "Adobe reader couldn't open helloworld.pdf because it's not either a supported file type or because the file has been damaged". I noticed this error occurs due to presence of html contents in pdf document. I am sending you pdf document as link https://dl.dropbox.com/u/45895040/helloworld.pdf.
If pdf is generated in Mac OS X, it opens sucessfully there
For better understanding just try to follow the steps as mentioned in Zend_pdf document throws error in magento due to presence of html contents.
Can anyone guide me how to set headers properly so that generated pdf can be opened on any browser irrespective of any Operating System.
回答1:
Add the following line of code right before the echo statement:
ob_end_clean();
That should do the trick.
来源:https://stackoverflow.com/questions/12279768/zend-pdf-document-issue-in-windows-7