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

Hi, I have a Mason application which shows result in table form. Now I need a link/button to export the result to pdf. Means when user click on the link/button, it will prompt open/save file dialog box. Any solution is appreciable.
  • Comment on How to create a pdf download link using Mason?

Replies are listed 'Best First'.
Re: How to create a pdf download link using Mason?
by moritz (Cardinal) on Jun 08, 2012 at 10:43 UTC
      Thanks for your reply. But just change the content-type is not worked. It ask to download the file, but when we try to open it in adobe reader, it shows error message as it is not a supported format. I think its because we are trying to open a text file using adobe.

      Below is the code I tried.

      <%init>
      $r->content_type('application/pdf');
      $r->headers_out->{'Content-disposition'} = "attachment; filename=report.pdf";
      $m->print('test');
      </%init>

        'test' isn't a valid PDF file. If you are actually trying to serve a PDF file, open it and send the content appropriately. If you simply think you can send any text and have Adobe PDF reader open it as a PDF file, you're mistaken. In that case you'd need to create a PDF then serve it.

Re: How to create a pdf download link using Mason?
by locked_user sundialsvc4 (Abbot) on Jun 08, 2012 at 14:28 UTC

    By far the easiest way to grok this sort of magic is simply to go to a site that is now doing what you want, and then to examine the HTML response-packet that was returned using the browser’s own built-in (or add-on...) debugging facilities.   The secret sauce to this particular problem is, indeed, the specifying of content-type and/or disposition in the HTML header.   But a concrete example is worth a thousand guesses, and in this case it is very easily obtained.