简体   繁体   English

Windows 7中的zend_pdf文档问题

[英]zend_pdf document issue in windows 7

I am using zend_pdf to generate pdf in magento 1.7 and I have tried something like 我正在使用zend_pdf在magento 1.7中生成pdf,并且尝试了类似的方法

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". 现在的问题是,在Windows 7上生成Pdf时,它无法打开,并引发错误消息:“ Adob​​e Reader无法打开helloworld.pdf,因为它既不是受支持的文件类型,也不是因为文件已损坏”。 I noticed this error occurs due to presence of html contents in pdf document. 我注意到此错误是由于pdf文档中存在html内容而发生的。 I am sending you pdf document as link https://dl.dropbox.com/u/45895040/helloworld.pdf . 我向您发送pdf文档,链接为https://dl.dropbox.com/u/45895040/helloworld.pdf

If pdf is generated in Mac OS X, it opens sucessfully there 如果在Mac OS X中生成了pdf,则会在其中成功打开

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 . 为了更好地理解,请尝试按照Zend_pdf文档中提到的步骤进行操作, 因为存在html内容会导致magento错误

Can anyone guide me how to set headers properly so that generated pdf can be opened on any browser irrespective of any Operating System. 谁能指导我如何正确设置标题,以便可以在任何浏览器上打开生成的pdf,而与任何操作系统无关。

Add the following line of code right before the echo statement: 在echo语句之前添加以下代码行:

        ob_end_clean();

That should do the trick. 这应该够了吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM