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

I am unable to set the name of my PDF document. Instead I get the script name where I would like to set a different name. I tried setting the file name with the new method (i.e. my $pdf = PDF::API2->new( -file => "myfilename.pdf") ) but that does not work for me. I also tried using the info method, guessing that a 'File' => 'myfilename.pdf' option exists, but that doesn't work either. In both cases I am sending the output to a browser. The PDF document is what I want except for the script name "myscript.cgi" appearing in document file field instead of "myfilename.pdf". Also, the browser's page title field shows "myscript.cgi (application/pdf Object) - Mozilla Firefox" instead of the intended "myfilename.pdf". Any help is most welcome.
  • Comment on PDF::API2 script name instead of file name

Replies are listed 'Best First'.
Re: PDF::API2 script name instead of file name
by roboticus (Chancellor) on Aug 15, 2009 at 13:23 UTC

    I was going to mention that the PDF::API2 module uses the saveas method to set your file name. But then I noticed that you mention "browser". So I suspect that you're making a web app, in which case you're probably just not setting up the headers correctly in your response.

    ...roboticus
Re: PDF::API2 script name instead of file name
by jethro (Monsignor) on Aug 16, 2009 at 11:31 UTC
      Right. I tried:

      print CGI::header( -type => 'application/pdf',
      -Content_disposition => 'inline;filename=\"myfilename.pdf\"')

      but that did not work either. Nor did "-Content-disposition" with a hyphen instead of an underscore.

      Still perplexed.
        While the header name may be Content_Disposition the parameter seems to be -content_disposition, at least as shown in the thread I refered to.
Re: PDF::API2 script name instead of file name
by Anonymous Monk on Aug 15, 2009 at 20:40 UTC
    Yes, I am writing the PDF to the browser. Here is how I am setting the header using CGI:

    print CGI::header( -type => 'application/pdf',
    -disposition => 'inline;filename=\"myfilename.pdf\"');

    And here is how I set the "info" using PDF::API2:

    %h = $pdf->info( 'Author' => "$username",
    'Title' => "$ListTitle Donation Receipt $receiptno",
    'CreationDate' => "D:$pdfyear$pdfmon$pdfday$pdfhour$pdfmin$pdfsec",
    'Producer' => 'List Manager');

    I am still no further ahead with this problem.
      Why are you inventing a header (Disposition)?
        After my post I saw that refs on the net to the usage of "-disposition" are wrong. But I also tried "-Content_disposition" and that did not work either.

        Still perplexed.