I’ve been doing a good deal of PDF generation in Rails, and had to go through the process of comparing all the available techniques and frameworks in order to find the right solution for my needs.
Its great that there are so many tools out there, but it can be a daunting task to figure out which is best, which will scale, which will continue to grow and improve, and to evaluate the true ‘cost’ of free vs. commercial.
With all this info finally digested and sorted out, I was surprised when I got a client request to be able to add a banner to an existing pdf, and from what I can recall, none of the libraries I know about seem able to do this. Right now, I’m in the middle of googling the hell out of it, but haven’t found my silver-bullet answer yet. (maybe I should ask jeeves?)
I’ve done various searches and have come across a few categories of PDF tools:
- Wrappers to existing pdf generation tools like fpdf, and iText
- PDF Template tools where you build a pdf skeleton file, and bind values to it programmatically
- Pure Ruby PDF Generation tools
- PDF Readers and inspection tools
I did find a discussion about how this could work on Google Groups between Greg Brown creator of Prawn and Ruport, and James Healey developer of PDF::Reader, but that discussion basically ended with, “Yeah, that would be cool!”.
At this point I’m looking into the Origami library which is actually designed for pdf ‘security’ and testing, and isn’t explicitly designed for editing pdfs in this way, but at the moment its the leading candidate in my list.
Have I missed something? Is there an obvious way to do this in ruby/rails that I’m completely overlooking? (I haven’t looked very deeply at tools that shell out to the bigger libraries, but I wouldn’t rule them out)
The initial requirement was to be able to add a banner/header to an existing PDF, but I can see the complexities of determining how to shift the existing content down without screwing up all the formatting, so I think even being able to insert a coverpage might be a suffcient implementation for now. (Maybe I should be searching for pdf ‘merging’ instead of editing)
I’ll update you with my final solution in an upcoming blog post, and I’ll be covering all of the info I’ve learned on PDF Generation tools for Ruby and Rails at this year’s WindyCityRails Conference on September 12th. Drop by http://windycityrails.org to register. (early registration ends Aug 1st)