[Melbourne-pm] Delivering PDFs via CGI

David david at naturalpractice.com.au
Mon Jun 19 00:08:59 PDT 2006


Hi Leigh,

The best way I have found around this is to set the Content-Disposition
header when out putting the file. In Apache::Request this looks like:

    $request->content_type('application/pdf');
    $request->header_out("Content-Disposition" => "attachment;
filename=myfile.pdf");

(CGI.pm would use a simlar syntax)

This will prompt a download of the file, giving the end user the option
of saving or opening the file.

HTH.

David



Leigh Sharpe wrote:
> Hi All,
>  Is it just me or has this list been really quiet recently?
>  
> Can anybody tell me how to output PDF files to a browser properly?
> Specifically, I'm having trouble getting Internet Explorer to
> recognise them as PDFs.
> This, for example:
>  
>  #!c:\perl\bin\perl.exe
>  use warnings;
>  use strict;
>  my $filename="c:\\temp\\mypdf.pdf";
>  my $data;
>  print "content-type:application/pdf\n\n";
>  open (PDFFILE,"<$filename") or die "$!\n";
>  binmode PDFFILE;
>  binmode STDOUT;
>  my $size = -s "$filename";
>  read PDFFILE,$data,$size || die"$!\n";
>  close PDFFILE;
>  print $data;
>  
>  
> Works perfectly when accessed using Mozilla. Using IE, I just get a
> screen full of garbage.
> If I use a URL that ends in ".pdf", it works. eg, instead of
> http://localhost/cgi-bin/mime.cgi, use
> http://localhost/cgi-bin/mime.cgi?fred.pdf. All works fine.
> Is this a bug in my browser, or am I overlooking something here?
> I find the same problem with MS-Word documents. I need to have
> a paramater which ends in ".doc" in order to have IE open a word doc
> automatically.
>  
>  
>  
> Regards,
>              Leigh
>  
> Leigh Sharpe
> Network Systems Engineer
> Pacific Wireless
> Ph 9584 8966
> Mob 0408 009 502
> email lsharpe at pacificwireless.com.au
> <blocked::mailto:lsharpe at pacificwireless.com.au>
> web www.pacificwireless.com.au
> <blocked::http://www.pacificwireless.com.au/>
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/melbourne-pm/attachments/20060619/2eebec49/attachment.html 


More information about the Melbourne-pm mailing list