This post originated from an RSS feed registered with Ruby Buzz
by Bob Silva.
Original Post: Generating PDF Documents with Rails and PDFlib - Part I
Feed Title: Rails Video Tutorials
Feed URL: http://www.railtie.net/xml/rss/feed.xml
Feed Description: A growing collection of screencasts that show you how to use the many facets of the wonderful world of rails.
Generating PDF documents programmatically is probably one of the worse programming tasks I've had the pleasure to work on. It's not terribly difficult, it's just tedious and time consuming. Some of my applications need to print catalogs or reports upwards of 300+ pages in real-time, so speed is of the essence, unfortunately, the pure Ruby PDF::Writer isn't up to the job. PDFlib-Lite, (read the license before using), is a fast library, which in the lastest 6.0.3 release contains Ruby Bindings (albeit horribly broken).
Run the configure script. Use --help for additional options/language bindings. Your paths may be different, if you can't figure it out, switch to Windows.
On linux: PDFlib-Lite-6.0.3> ./configure --with-ruby=/usr/bin/ruby --with-rubyincl=/usr/lib/ruby/1.8/i686-linux
On MacOSX (you built your own Ruby right?):
PDFlib-Lite-6.0.3> ./configure --with-ruby=/usr/local/bin/ruby --with-rubyincl=/usr/local/lib/ruby/1.8/i686-darwin8.5.2
If you followed these instructions, the configure script should tell you that the Ruby bindings are active.
Ruby language binding for PDFlib: yes
Build the library, (the 'make test' is required for these instructions to work)
PDFlib-Lite-6.0.3> make
PDFlib-Lite-6.0.3> make test
PDFlib-Lite-6.0.3> make install
All right, so now you'd think it would work since you've installed it. Remember when I said the Ruby bindings were broken, besides the patch to get PDFlib to realize it has Ruby bindings, you also have to manually copy the library to your Ruby's site_ruby/ directory. Optionally, you can symlink the real library found in your /usr/lib or /usr/local/lib directory.
PDFlib-Lite-6.0.3> cd bind/pdflib/ruby
On linux: PDFlib-Lite-6.0.3/bind/pdflib/ruby> cp PDFlib.so /usr/lib/ruby/site_ruby/1.8
On MacOSX:
PDFlib-Lite-6.0.3/bind/pdflib/ruby> cp PDFlib.bundle /usr/local/lib/ruby/site_ruby/1.8