[Catalyst] Re: PDF creation in Catalyst?

Aristotle Pagaltzis pagaltzis at gmx.de
Wed Oct 22 20:50:25 BST 2008


* Kirby Krueger <kirbykr at u.washington.edu> [2008-10-22 20:20]:
> Can someone give me those few lines? :-)

    sub MyApp::Controller::Root::renderview : ActionClass('RenderView') {}

    sub MyApp::Controller::Root::end : Private {
        my $self = shift;
        my ( $c ) = @_;
        $c->forward( '/renderview' );
        if ( $c->req->param( 'pdf' ) ) {
            my @pdf_cmd = Text::ParseWords::shellwords( $c->config->{ pdf_cmd } );
            $c->res->content_type( 'application/pdf' );
            $c->res->body( IPC::Filter::filter( $c->res->body, @pdf_cmd ) );
        }
    }

And in `myapp.conf`:

    pdf_cmd prince -i html -s prince.css -o - -

Yes, PrinceXML <http://www.princexml.com/> costs $$$, *however*,
it renders HTML to PDF verbatim instead of requiring you to use
completely different stuff like FOP or LaTeX – which is an
especially big selling point if you’re looking to generate PDF
from a CMS-ish thing where users can enter HTML content. It also
supports pretty much all print-related CSS stuff, which includes
control over line breaks and the like, and also provides
proprietary CSS extensions to do things like page headers and
footers, page numbering, and so on. For us, the effort we avoided
of having to write PDF-specific code (the above lines are
literally the only PDF-related code in the app) and then maintain
it over more than made up for the price tag.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list