Installation of PDFLib on Rails

On a large project I’m working on we need to be able to import a (rather large) PDF and populate it’s fields from a database table, essentially. I looked into a few options like the built-in Ruby PDF generator PDF::Writer. PDF::Writer is good for generating PDF’s but not so good with importing existing documents for manipulation. Enter PDFLib. Unfortunately PDFLib is fairly expensive but it has everything I’m looking for. Probably one of the greatest features is it comes with a PDFLib Block Tool which allows you to add textfields anywhere on a PDF to be populated at a later time.

One nice thing about PDFLib is (for Ruby on Rails) you can install it into the plugins folder. This makes it so much easier than worrying about installing a package on your server, especially if your hosting your site on a shared environment (like Dreamhost).

I’m a fairly newer Ruby on Rails programmer and haven’t used plugins very much so I thought it would be tough to install. This proved not the case. Here’s the simple instructions:

1. Download the Ruby bindings from the PDFLib site depending on which system you’re using.

2. Extract the compressed file

3. Place the pdflib library file into your Rails App’s plugins vendor folder. On Mac OSX the library file is pdflib.library, on Linux the library file is pdflib.so.

If you’re like me, you do development on your local Mac system and upload the site to your host, which is a Linux/Apache server. In this case make sure to put the pdflib.so library file in the Rails app which is on the server and the pdflib.library file in the Rails app on your local machine.

That’s it!

Now that the library is installed, you can test the examples that come with pdflib and start to build your own PDF application.


About this entry