artist has asked for the wisdom of the Perl Monks concerning the following question:

I serve the PDF documents on the fly with perl program, from webserver. On Macintosh, since it sees .pl file rather than .pdf, but gets the header for PDF in the file, it tries to open the default viewer for PDF rather than Adobe Acrobat.

How I can send appropriate header so that it can open PDF with Adobe Acrobat? If user associate the extension .pl with Acrobat, it works fine. I like to get Perl side solution to avoid this route.

Thanks. Update: (after 10 Minutes) Here is my origianl code:

sub display_pdf { my $file = shift; print "Content-Type: application/pdf\n\n"; open(IN, "$file") || die "cannot open $file"; binmode(IN); while(<IN>){ print; } close(IN); }

It works fine with PC without any problem.

Replies are listed 'Best First'.
Re: Mac and PDF
by ikegami (Patriarch) on Nov 24, 2004 at 16:43 UTC
    Before resorting to the extention (if at all), the web browser uses the Content-Type field to determine what is the data being sent by the web server. It should simply be a matter of setting the content type to "application/pdf". I've never done it for PDFs before, but I've have scripts with the .cgi extention output images of various type (PNG, JPG, GIF) without any problem when I set Content-Type properly.
Re: Mac and PDF
by stvn (Monsignor) on Nov 24, 2004 at 18:15 UTC

    Try doing something like this in the URL that serves the PDF.

    http://www.myhost.com/cgi-bin/display_pdf.pl/something.pdf?key=value
    The additional '/something.pdf' will show up as path_info in most cases, and all else will be as expected. The result is that the mac browser will likely see something.pdf as the filename and download it as such.

    The problem is really that on on macs (pre-OSX), file extensions are for the most part ignored in favor of the resource-fork of the file (which surely your pdf will not have).

    -stvn
Re: Mac and PDF
by traveler (Parson) on Nov 24, 2004 at 23:27 UTC
    How I can send appropriate header so that it can open PDF with Adobe Acrobat? If user associate the extension .pl with Acrobat, it works fine. I like to get Perl side solution to avoid this route.

    Hopefully you can't :-) The idea is that the user determines what application handles what type of content -- in this case PDF. You can have the user assoicate .pdf with acrobat and that should work, too.

    That said, you can try setting the Content-Type to application/x-adobe-acrobat. It might be supported on your clients.