Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate pdf from Rails 3 - what tool to choose?

I need to be able to render some views as PDFs from a Rails 3 project. I've never before used PDF generation techniques with ruby/rails, so I researched a few popular approaches such as Prawn and PDF::Writer, but all the examples and articles I found so far seem outdated and only applicable for rails 2.x. I haven't yet seen a working Rails3 example; tried myself installing prawn and the prawnto gems and reproducing the example described in this Railscasts episode, but I'm getting error of prawnto method not being recognized. I'm uncertain of whether this was an implementation error or just a sign of incompatibility, but seeing other people share on the web that prawn is no longer working for them in Rails3 I didn't bother tracing the code further.

Has anyone found a working reliable solution for pdf generation in Rails3? Could you possibly share it or point me to external resources and documentation? Big thanks!

like image 360
svilenv Avatar asked Nov 07 '10 13:11

svilenv


2 Answers

New answer to an old question, in case others stumble across this: WickedPDF (which uses wkhtmltopdf just like PDFkit) makes this a snap.

https://github.com/mileszs/wicked_pdf

like image 199
Thilo Avatar answered Sep 29 '22 05:09

Thilo


Prawn does work with Rails 3. I have personally used it with no problems. You do have to get the latest versions of the gem and the prawnto plugin for rails.

PDFkit does have the advantage of using the Webkit rendering engine, so you get to use CSS to define your layouts, and you get matching web pages for free with Safari and Chrome. It has a slightly nicer learning curve than Prawn.

like image 36
edgerunner Avatar answered Sep 29 '22 05:09

edgerunner