
jir2004 at qatar-med
Nov 6, 2012, 3:07 AM
Post #1 of 4
(505 views)
Permalink
|
|
trouble with a pdf attachment
|
|
Hello all, I'm trying to send a pdf attachment to the browser. I found an example online of a text/csv attachment. sub this_works{ my($self, $c) = @_; my $csv = "1,5.99\n2,29.99\n3,3.99\n"; $c->res->content_type('text/comma-separated-values'); my $filename = 'Important Orders.csv'; $c->res->header('Content-Disposition', "attachment; filename=$filename"); $c->res->body($csv); } Which gives back a comma separated file as expected. However, when I try to send back a pdf I get an empty file. sub attach_pdf{ my($self, $c, $fileholder, $file, $name) = @_; open(DLFILE, "<$file") or die $c->log->debug("Couldn't open file! $!"); my @fileholder = <DLFILE>; close (DLFILE) or die $c->log->debug("Couldn't close file! $!"); $c->res->content_type('application/pdf'); $c->res->header('Content-Disposition', "attachment; filename=$name"); $c->res->body("@$fileholder"); } If I try it without the content and the header I get back what the pdf file looks like in vim, so I know its reading the file in. Nearly this exact script works with a perl cgi script, but I haven't figured it out for catalyst yet. Any help would be very appreciated. Best, Jillian _______________________________________________ Catalyst-dev mailing list Catalyst-dev [at] lists http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
|