Re: Getting gibberish, sometimes, in PDF output
| From: | Sarah Gray | Date: | Mon, 21 Oct 2002 18:15:59 +0000 |
| Subject: | Re: Getting gibberish, sometimes, in PDF output | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120781@lists.php.net to get a copy of this message | ||
My file outputs in NS4.79 but not IE6 (although it used to work in IE no
problem. not sure why it stopped). These are my last lines of code:
pdf_close($p);
$buf = pdf_get_buffer($p);
$len = strlen($buf);
$filename = "Certificate.pdf";
header("Content-type: application/pdf");
header("Content-disposition:inline;filename=$filename");
header("Content-length: $len");
print $buf;
pdf_delete($p);
?>
(I'm not using sessions).
Anything?
thanks,
s.
Matt Schroebel wrote:
>
> > -----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");