RE: [PHP] Getting gibberish, sometimes, in PDF output
| From: | Matt Schroebel | Date: | Mon, 21 Oct 2002 17:50:07 +0000 |
| Subject: | RE: [PHP] Getting gibberish, sometimes, in PDF output | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-120775@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Sarah Gray [mailto:sarah@fabled.net]
> Sent: Monday, October 21, 2002 12:21 PM
> To: PHP
> Subject: [PHP] Getting gibberish, sometimes, in PDF output
>
>
> hi
> I'm generating a pdf file and giving users a link to the file
> (an online
> certificate). The link is just a regular link with a query string.
>
> Sometimes in the browser the pdf file opens correctly, and other times
> the page spews out gibberish (uncompiled).
>
> I am including the header header("Content-type: application/pdf"); in
> the file and it is on the first line (before includes, etc.).
>
> This is the first time I am outputting pdf files and suspect that
> probably I am missing something simple -- a step, call to a plugin,
> header, something. Can anyone tell me what that might be?
Make sure to send a content-length header, or IE won't like the pdf. IE
has this terrible habit of remembering the content-type within a window
of the browser, so if you ever had sent the page without the
content-type, then IE will treat it as text and you get gibberish. The
same is true in reverse -- if you get a parse error and had previously
sent a content-type header, you'll get a broken icon image unless you
close the window and re-open the page.
Also, you may want to move the content-type header to a place right
before you output the pdf, so that if there are parse errors, the
browser will show them and not try to send the page to Aacrobat.
These are the headers I send:
header('Content-type: application/pdf');
header("Content-Disposition: inline; filename=$fileName");
header("Content-Length: $length");