Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Should I create a new view for rendering a pdf in browser?

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


steve at matsch

Nov 9, 2011, 6:34 AM

Post #1 of 7 (299 views)
Permalink
Should I create a new view for rendering a pdf in browser?

Hello all,

My question is fairly straightforward - If I want to render a pdf in a
browser, should I create a new Catalyst View?

The background on this is that we think that rather than rendering an
HTML version of these reports, and subsequently converting them to pdf,
just create the pdf on the fly and render it in the browser.

Extra credit for recommendations on pdf tools for this type of thing.
We've looked at PDF::Create, PDF::API2, PDF::Reuse, and also Prince (if
we decide to convert from HTML).

Thanks - Steve

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alec.taylor6 at gmail

Nov 9, 2011, 6:50 AM

Post #2 of 7 (293 views)
Permalink
Re: Should I create a new view for rendering a pdf in browser? [In reply to]

< looks left
looks right >

._. interested in displaying PDFs without a client-side PDF plugin?

On Thu, Nov 10, 2011 at 1:34 AM, Steve <steve [at] matsch> wrote:
> Hello all,
>
> My question is fairly straightforward - If I want to render a pdf in a
> browser, should I create a new Catalyst View?
>
> The background on this is that we think that rather than rendering an HTML
> version of these reports, and subsequently converting them to pdf, just
> create the pdf on the fly and render it in the browser.
>
> Extra credit for recommendations on pdf tools for this type of thing.  We've
> looked at PDF::Create, PDF::API2, PDF::Reuse, and also Prince (if we decide
> to convert from HTML).
>
> Thanks - Steve
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


jens.gassmann at atomix

Nov 9, 2011, 6:59 AM

Post #3 of 7 (297 views)
Permalink
Re: Should I create a new view for rendering a pdf in browser? [In reply to]

Hi Steve,

> My question is fairly straightforward - If I want to render a pdf in a
> browser, should I create a new Catalyst View?

Yes.

> The background on this is that we think that rather than rendering an
> HTML version of these reports, and subsequently converting them to pdf,
> just create the pdf on the fly and render it in the browser.

I use Catalyst::View::Wkhtmltopdf - maybe Prince is better, but it is
not open source like wkhtml. Also Catalyst::View::Wkhtmltopdf supports
Template Toolkit and could render your Templates without much
modifications.

http://search.cpan.org/perldoc?Catalyst::View::Wkhtmltopdf

Best regards,
Jens



_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


steve at matsch

Nov 9, 2011, 7:16 AM

Post #4 of 7 (294 views)
Permalink
Re: Should I create a new view for rendering a pdf in browser? [In reply to]

Alec - Good point. I've taken for granted that everyone's browser has
these plugins. Perhaps conversion is the best option.

Steve


On 11/9/2011 9:50 AM, Alec Taylor wrote:
> < looks left
> looks right>
>
> ._. interested in displaying PDFs without a client-side PDF plugin?
>
> On Thu, Nov 10, 2011 at 1:34 AM, Steve<steve [at] matsch> wrote:
>> Hello all,
>>
>> My question is fairly straightforward - If I want to render a pdf in a
>> browser, should I create a new Catalyst View?
>>
>> The background on this is that we think that rather than rendering an HTML
>> version of these reports, and subsequently converting them to pdf, just
>> create the pdf on the fly and render it in the browser.
>>
>> Extra credit for recommendations on pdf tools for this type of thing. We've
>> looked at PDF::Create, PDF::API2, PDF::Reuse, and also Prince (if we decide
>> to convert from HTML).
>>
>> Thanks - Steve
>>
>> _______________________________________________
>> List: Catalyst [at] lists
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>
>

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


drew at drewtaylor

Nov 9, 2011, 3:05 PM

Post #5 of 7 (287 views)
Permalink
Re: Should I create a new view for rendering a pdf in browser? [In reply to]

On Thu, Nov 10, 2011 at 1:59 AM, Jens Gassmann <jens.gassmann [at] atomix> wrote:
>
> I use Catalyst::View::Wkhtmltopdf  - maybe Prince is better, but it is
> not open source like wkhtml. Also Catalyst::View::Wkhtmltopdf  supports
> Template Toolkit and could render your Templates without much
> modifications.

Thanks, I had not heard of Wkhtmltopdf. Noted for future reference.
I've read many good things about Prince, but one thing it is not is
cheap.

Drew

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


bobtfish at bobtfish

Nov 9, 2011, 3:07 PM

Post #6 of 7 (288 views)
Permalink
Re: Should I create a new view for rendering a pdf in browser? [In reply to]

On 9 Nov 2011, at 14:34, Steve wrote:
> My question is fairly straightforward - If I want to render a pdf in
> a browser, should I create a new Catalyst View?

Yes. In a perfect world, you'd just say $c->stash( current_view =>
'PDF' ) (and set a filename?) to make a pdf...

>
> The background on this is that we think that rather than rendering
> an HTML version of these reports, and subsequently converting them
> to pdf, just create the pdf on the fly and render it in the browser.
>
> Extra credit for recommendations on pdf tools for this type of
> thing. We've looked at PDF::Create, PDF::API2, PDF::Reuse, and also
> Prince (if we decide to convert from HTML).

Depends how dirty you want to be :_)

Doing something 'proper' with one of these (or also, take your XHTML,
apply XSLT => docbook, then make a pdf?) totally works, and if you're
prepared to put the effort in, you can make really nice documents..

But _if_ you can deal with something ugly but workable - then just
subclass your HTML view, after process write $c->req->body out to a
tempfile and run html2ps | ps2pdf on it! (Then read that back in and
replace the body) This is really dirty (and kinda slow for big pages),
but with a few appropriate options and some CSS to cut out the bits
that shouldn't be in the pdf - it works well..

I use this technique for all of our invoices, as I don't really care
how they look :)

Cheers
t0m


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


domm at cpan

Nov 9, 2011, 11:09 PM

Post #7 of 7 (278 views)
Permalink
Re: Should I create a new view for rendering a pdf in browser? [In reply to]

Hi!

On Wed, Nov 09, 2011 at 03:59:50PM +0100, Jens Gassmann wrote:

> I use Catalyst::View::Wkhtmltopdf - maybe Prince is better, but it is
> not open source like wkhtml. Also Catalyst::View::Wkhtmltopdf supports
> Template Toolkit and could render your Templates without much
> modifications.

If you don't want to use an external binary, you could also use Webkit
directly via Gtk3::Webkit though I'm not sure how stable / performant
this is. Emmanuel gave a talk about this last weekend during the Twin
City Perl Workshop:
http://conferences.yapceurope.org/tcpw2011/talk/3836

Here's his script to take a screenshot in various formats:
https://github.com/potyl/Webkit/blob/master/screenshot.pl

I probably wouldn't embed this directly into Catalyst, but set up a
seperate service, so maybe just using wkhtmltopdf is in fact simpler...

Greetings,
domm

--
#!/usr/bin/perl http://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.