[Catalyst] generating and redirecting to pdfs

Steve Rippl rippls at woodlandschools.org
Fri Oct 23 14:23:27 GMT 2009


On Wed, 2009-10-21 at 09:42 +1000, Jason Galea wrote:

>   my $doc = HTML::HTMLDoc->new( 'mode' => 'file', 'tmpdir' =>
> $self->config->{tmp_dir} );
>   $doc->set_page_size($self->config->{page_size});
>   $doc->set_header(@{$self->config->{header}});
>   $doc->set_footer(@{$self->config->{footer}});
>   $doc->set_html_content($output);
> 
>   my $pdf = $doc->generate_pdf();
> 
>   unless ( $c->response->content_type ) {
>     $c->response->content_type('text/pdf; charset=utf-8');
>   }
> 
>   $c->res->header( 'Content-Disposition' =>
> 'attachment;filename='.$c->stash->{pdf_filename} );
> 
>   $c->response->body($pdf->to_string());
> 
>   return 1;
> }

Thanks for this!  I did get this working, the only change I seemed to
have to make was  

$c->response->content_type('application/pdf');

In order to get my browser to open it using a pdf reader (with
'text/pdf' it was using a text editor).

Thanks again!

Steve







More information about the Catalyst mailing list