Disclaimer: this is a really passionate post about PDF generation in Ruby on Rails
If you ever tried to generate PDFs in one of your Ruby on Rails projects you probably know plenty different ways to get PDFs out of your Ruby on Rails app: Prawn, Apache FOP, iText et cetera.
I’ve worked with Prawn, Apache FOP and iText - all these solutions are completly impractical. Here is why:
- Prawn: for me, the Prawn DSL doesn’t work well with separation of concern: if you don’t watch out you’ll end up mixing your style- and layout code. The result might be a working and great looking PDF, but if you are after maintainability this is a no-go.
- Apache FOP: great! You need a diploma just to write proper XSLT’s, and the toolchain for rapid-prototyping using XML + XSLTs is practically non-existing. There are GUI based tools out there but they are either expensive and/ or a usability nightmare. Just not worth it.
- iText: Just like Prawn, but worse. You most likely will have to write Java to get it working. Ugh!
I’m sure there are a many many ways to create workflows to work with either of these libraries, but why bother? Why not just use HTML + CSS for PDFs?
HTML + CSS is well known, nearly every 16 year old pupil can create a HTML page. You don’t need to know programming at all, and can easily delegate the maintaining task, since it’s so easy to edit HTML files.
And since wkhtmltopdf and PDFKit are out, there’s no excuse not using those well known, robust technologies for this task.
Bottom line: Just last week I converted one of my projects from Apache FOP to PDFKit. The conversion was easily done and it saved me a ton of time already since I could delegate the creation- and maintaining of PDFs nearly completely on my client.
Huge success!
PDFKit & wkhtmltopdf to the rescue ;)
Interested? This post @ metaskills might just get you started.
sidenote: at the end of the day, the only thing that count’s getting it done. Thus choosing the right tool for the job is more important than your personal opinion.