0

今天我开始尝试使用基于 PHP 的 PDF 生成器。我尝试了 TCPDF,它在大多数情况下都可以正常工作,尽管它似乎有点慢。但是,当我在 Internet Explorer 8 中加载生成我的 PDF 的 PHP 文件时,我看到一行一行的奇怪字符。然而,Chrome 将其识别为 PDF。

我假设我必须设置一个特殊的 MIME 类型来告诉 IE 它应该将页面输出解释为 PDF 文件。如果是,我该怎么做?

4

5 回答 5

2

放置“application/pdf”或“application/octet-stream”mime 类型可能会有所帮助。请记住,“application/octet-stream”将强制下载文件,并可能阻止它在浏览器中打开。

如果你想知道,你可以这样做:

header('Content-type: application/octet-stream');
于 2010-06-27T15:44:51.200 回答
2

I had this problem also but what I did to get it work is I added

 exit();

at the end of pdf output.

于 2010-08-03T05:33:26.470 回答
0

对于动态生成的内容,您需要以不同的方式处理 IE。看这篇文章,

http://support.microsoft.com/default.aspx?scid=kb;en-us;293792

在我的代码中,我这样做,

    if(isset($_SERVER['HTTP_USER_AGENT']) AND ($_SERVER['HTTP_USER_AGENT']=='contype')) {
            header('Content-Type: application/pdf');
            exit;
    }

这个问题也可以解释你提到的缓慢,因为你的页面实际上在没有这个逻辑的情况下多次发送整个 PDF。

于 2010-06-27T17:15:29.043 回答
0

@Pieter:我在使用 tcpdf(使用 fpdi)时遇到了同样的问题,并使用 ajax 调用加载了生成 pdf 的页面。我更改了javascript以使用window.location加载页面,问题消失了,性能也好多了。我相信其他两张海报在文档标题导致问题的想法上是正确的。就我而言,由于 ajax 调用,标头未应用于整个文档,并导致问题。希望这可以帮助。

于 2010-07-06T04:51:58.130 回答
0

I found this to be a problem too, and for me this all hinged on the code:

if (php_sapi_name( != 'cli') {

on line 7249 of the tcpdf.php file.
I commented this 'if' statement (and related '}')and all works fine for my other browser and ie8 Hope this helps

于 2010-07-30T11:45:53.670 回答