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

Hey there everyone, I asked a question in the chatterbox and got a few ideas, but they didn't lead me anywhere, but thank you regardless.

The problem is that if the user viewing a PDF tries to save or email it from Acrobat, it saves as "script.pl" but is actually the PDF. If the extension is changed, it'll open as a PDF.

$| = 1; # turn off buffering of stdout open (FILE, "$path"); # Opens file immediately upon being clicked, but doesn't allow proper +saving of extensions when emailed from in Acrobat $page = $q->header(-type=>'application/pdf', -disposition=>'inline +') . $q->start_html(-title=>$news_id.".pdf", -style=>{-src=>'../style +.css' }) . $q->start_form(-name=>'main') . $q->end_form(); while (<FILE>) { print $_; } $page .= $q->end_html(); $| = 0; #turn on buffering of stdout print $page;
I've tried a multitude of header variations, but nothing changes. I thought by providing the script, more light may be shed on it. Any suggestions?

Thanks!

Hugh

Replies are listed 'Best First'.
Re: Print PDF Problem
by tilly (Archbishop) on Jul 11, 2008 at 21:11 UTC
    When you have a CGI program returning a file that is not inline you can control the filename by passing -attachment => $filename into the header method call. I have never included one inline in a web page, but it is worth trying.

    If that doesn't work, another solution is to change the URL to include a path after your script. That is instead of accessing a url of the form: http://yoursite/some/path/to/script.pl you'd have them access one of the form http://yoursite/some/path/to/script.pl/somefile.pdf. That will still call your CGI script, but now the client will think the filename is somefile.pdf.

Re: Print PDF Problem
by thezip (Vicar) on Jul 11, 2008 at 21:11 UTC

    I've used a header such as this with success:

    my $header = qq(Content-type:application/pdf\n) . qq(Content-Disposition: attachment;filename=foo.pdf\n\n); print $header;

    YMMV, so please adapt as needed.


    Your wish is my commandline.
Re: Print PDF Problem
by Heffstar (Acolyte) on Jul 11, 2008 at 21:53 UTC
    Thanks for the suggestions, however, in both cases I have a window open (which is supposed to happen) but a dialog box opens for the user to choose Save, Open, etc..

    The end result is supposed to display the pdf in the window that opens.

    I've very new to perl, so please forgive my poor knowledge of CGI programming :P

    Thanks again,

    Hugh