Generating PDFs from Rails

29 views
Skip to first unread message

ChrisPaul

unread,
May 29, 2012, 7:33:36 PM5/29/12
to boston-r...@googlegroups.com
Our customers would like nicely designed, printable reports. Does anyone have recommendations for generating PDFs for them from our Rails 2.3.14 app? 

I used prawnto almost 3 years ago. It had some rough edges but worked.

Thanks,
Chris

ben wiseley

unread,
May 29, 2012, 7:35:22 PM5/29/12
to boston-r...@googlegroups.com
We used this: https://github.com/mileszs/wicked_pdf

Upside: really simple, uses an erb template solution for design

Downside: can be hard to deploy on a server, has limitations on what you can do in the PDF

-ben


--
You received this message because you are subscribed to the Boston Ruby Group mailing list
To post to this group, send email to boston-r...@googlegroups.com
To unsubscribe from this group, send email to boston-rubygro...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/boston-rubygroup

Allen Madsen

unread,
May 29, 2012, 7:43:08 PM5/29/12
to boston-r...@googlegroups.com
My lazy way to answer questions like this:

Dylan Cashman

unread,
May 29, 2012, 7:59:09 PM5/29/12
to boston-r...@googlegroups.com
I'm having trouble finding prawnto online, I don't know if it's been deprecated or not.  I use just prawn all the time (not sure if thats just a different name for the same project: http://prawn.majesticseacreature.com/), though, and I really like it.  I prefer it to html-style layouts because it's designed for a more statically-sized page, so it's pretty easy to make interesting layouts.  I don't remember having any trouble getting it to work correctly on a server.  I started with the railscast: http://railscasts.com/episodes/153-pdfs-with-prawn

We've also used pdfkit a bit: https://github.com/pdfkit/PDFKit
Similar to wicked_pdf, you can use an erb template.  It actually has a middleware that lets you have any html page be printable as a pdf, and you can specify a different layout and css for your pages as pdfs so they print out all nice.  Again, railscasts explains it much better than I do: http://railscasts.com/episodes/220-pdfkit

On Tue, May 29, 2012 at 7:35 PM, ben wiseley <wise...@gmail.com> wrote:



--
Dylan Cashman
Annkissam - Mission Driven Systems
www.annkissam.com

One Broadway, 14th Floor
Cambridge, MA 02142
Cell (preferred): 617-999-3634
Office: 617-401-2480, ext. 708
Fax: 617-507-5922

Daniel Choi

unread,
May 29, 2012, 8:12:26 PM5/29/12
to boston-r...@googlegroups.com, dhc...@gmail.com
How about iText with JRuby? I have no experience with this route yet,
but that's what I plan to use for a future project.


On Tue, May 29, 2012 at 07:59 PM, Dylan Cashman <dylan....@annkissam.com> wrote:

> from: Dylan Cashman <dylan....@annkissam.com>
> date: Tue, May 29 07:59 PM -04:00 2012
> to: boston-r...@googlegroups.com
> reply-to: boston-r...@googlegroups.com
> subject: Re: [boston.rb] Generating PDFs from Rails
----
Sent from vmail
https://github.com/danchoi/vmail

Mauricio Linhares de Aragao Junior

unread,
May 29, 2012, 8:25:43 PM5/29/12
to boston-r...@googlegroups.com
I wouldn't use iText for this, it's way too barebones and you would have to learn it all ( but it's an awesome library, I'm using it in a project for quite some time and it works like a charm).

If you want designed PDFs the best tool is surely iReport/JasperReports, can't search for it right now but you can surely find a way to integrate the jasper server in a rails app.

Enviado via iPhone

Michael Breen

unread,
May 29, 2012, 8:42:04 PM5/29/12
to boston-r...@googlegroups.com
I have a client app, running Rails 2.3, that generates PDFs using Prince via the princely gem. Granted Prince is not cheap but fortunately the client was willing to spend the money.


Daniel Choi

unread,
May 29, 2012, 8:47:28 PM5/29/12
to boston-r...@googlegroups.com, dhc...@gmail.com
But I already bought an iText In Action book!

On Tue, May 29, 2012 at 08:25 PM, Mauricio Linhares de Aragao Junior <linhares...@gmail.com> wrote:

> from: Mauricio Linhares de Aragao Junior <linhares...@gmail.com>
> date: Tue, May 29 09:25 PM -03:00 2012
> to: "boston-r...@googlegroups.com" <boston-r...@googlegroups.com>
> reply-to: boston-r...@googlegroups.com
> subject: Re: [boston.rb] Generating PDFs from Rails
>
> I wouldn't use iText for this, it's way too barebones and you would have to learn it all ( but it's an awesome library, I'm using it in a project for quite some time and it works like a charm).
>
> If you want designed PDFs the best tool is surely iReport/JasperReports, can't search for it right now but you can surely find a way to integrate the jasper server in a rails app.
>
> Enviado via iPhone
>

Maurício Linhares

unread,
May 29, 2012, 9:56:28 PM5/29/12
to boston-r...@googlegroups.com, dhc...@gmail.com
And it's a great reading!

Highly recommended if you need customized PDF generation, iText is probably the best OSS library available for this.

On the iReport thing, you can connect from Ruby to a JasperServer using this gem - https://github.com/gunark/jasperserver-client - it's a bit old, but with a couple of changes should definitely be able to connect to it. 

You can also integrate it directly using JRuby but this is going to require you to know Java (this is really easy if you do know Java, btw).

The usual workflow is build the report using the iReport designer ( http://jasperforge.org/projects/ireport - looks like QuickReports if you have ever seen it) and then generate it using the Jasper library. The output selection is very wide, from PDF (great for printing), to Office formats, HTML, plain text, all there. Using something like this you avoid having to build the PDF manually with code.

Jay McGaffigan

unread,
May 29, 2012, 10:07:39 PM5/29/12
to boston-r...@googlegroups.com, boston-r...@googlegroups.com
How about princexml?

Jay

Kevin Bedell

unread,
May 30, 2012, 8:07:33 AM5/30/12
to boston-r...@googlegroups.com
I recommend wicked_pdf as well. You create erb templates (though I
believe you may be able to use haml if you'd like) and it generates
pdf's that reflect the erb. We have it deployed on heroku and once you
understand how to set it up it's pretty easy to work with.

-k

On Tue, May 29, 2012 at 7:35 PM, ben wiseley <wise...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages