zend_pdf document issue in windows 7

青春壹個敷衍的年華 提交于 2019-12-12 06:27:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!