Windows 7中的zend_pdf文档问题 [英] zend_pdf document issue in windows 7

查看:95
本文介绍了Windows 7中的zend_pdf文档问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用zend_pdf在magento 1.7中生成pdf,并且我尝试了类似的方法

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;
 }

现在的问题是,在Windows 7上生成Pdf时,它无法打开,并引发错误消息:"Adob​​e Reader无法打开helloworld.pdf,因为它既不是受支持的文件类型,也不是因为文件已损坏".我注意到此错误是由于pdf文档中存在html内容而发生的.我正在将pdf文档作为链接发送给您 https://dl.dropbox.com/u/45895040/helloworld.pdf .

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.

如果在Mac OS X中生成了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.

任何人都可以指导我如何正确设置标题,以便可以在任何浏览器上打开生成的pdf,而与任何操作系统无关.

Can anyone guide me how to set headers properly so that generated pdf can be opened on any browser irrespective of any Operating System.

推荐答案

在echo语句之前添加以下代码行:

Add the following line of code right before the echo statement:

        ob_end_clean();

应该可以解决问题.

这篇关于Windows 7中的zend_pdf文档问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆