문제

Today I started experimenting with PHP-based PDF generators. I tried TCPDF and it works fine for the most part, although it seems to be a little slow. But when I load the PHP file that generates my PDF in Internet Explorer 8, I see lines and lines of weird characters. Chrome however recognizes it as a PDF.

I'm assuming that I have to set a special MIME type to tell IE that it should interpret the page output as a PDF file. If yes, how can I do this?

도움이 되었습니까?

해결책

putting "application/pdf" or "application/octet-stream" mime types might help. keep in mind that "application/octet-stream" will force download of the file and might prevent it from opening in the browser..

in case you wonder, you can do it like that:

header('Content-type: application/octet-stream');

다른 팁

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

 exit();

at the end of pdf output.

You need to handle IE differently for dynamic-generated content. See this article,

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

In my code, I do this,

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

This problem may also explain slowness you mentioned because your page actually sends the whole PDF multiple times without this logic.

@Pieter: I was experiencing the same issue using tcpdf (with fpdi), and loading the page that was generating the pdf using an ajax call. I changed the javascript to load the page using window.location instead, and the issue went away and the performance was much better. I believe that the other two posters are correct in the idea that the document header is causing the issue. In my case, because of the ajax call, the header was not being applied to the whole document, and causing the issue. Hope this helps.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top