October 3, 2004

PDF via CGI::Application

I'm working on a little application which requires the generation of PDF files. Overseeing the whole app is CGI::Application. I was rather perplexed as to how to set header-type to something other than 'text/html'. It turns out that the answer is not $self->header_type('application/pdf'). You will get an "invalid header_type 'application/pdf'" error. The answer, courtesy of weierophinney is

Kind of unintuitive, but I can guarantee that it works.

More info from Adam Gent also shows how to name the downloaded file:

Through the header_props method is C::A, which goes via CGI.pm


So you can then do

$webapp->header_props(-type => "text/comma-separated-values",
-attachment => "download.csv");

Should work fine.

You can also do this for zip and pdf files, if you set the correct header type, i.e., application/zip, application/pdf

Posted by torque at October 3, 2004 5:27 PM | TrackBack

What package/module are you using that actually creates the PDF file?

Posted by: Name at February 11, 2005 11:43 AM

Good job!

Posted by: Markus at December 11, 2006 10:49 AM

Pop trio Atomic Kitten will reform to play a concert in support of jailed Liverpool football fan Michael Shields...

Posted by: Wyatt Osullivan at December 12, 2006 5:57 AM

Good job!

Posted by: Markus at December 12, 2006 7:43 PM
Post a comment

Remember personal info?