<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>I.NFECTIO.US: Generating PDF Documents with Rails and PDFlib - Part I</title>
    <link>http://i.nfectio.us/articles/2006/04/02/generating-pdf-documents-with-rails-and-pdflib-part-i</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>"Nothing in life is worth doing if you have no life while doing it"</description>
    <item>
      <title>Generating PDF Documents with Rails and PDFlib - Part I</title>
      <description>&lt;br /&gt;
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, (&lt;a href="http://www.pdflib.com/products/pdflib/info/PDFlib-Lite-license.pdf"&gt;read the license before using&lt;/a&gt;), is a fast library, which in the lastest 6.0.3 release contains Ruby Bindings (albeit horribly broken).

&lt;br /&gt;&lt;br /&gt;
&lt;u&gt;&lt;h2&gt;Installing PDFlib-Lite&lt;/h2&gt;&lt;/u&gt;&lt;br /&gt;
Installing PDFlib is similar on Linux and MacOSX.
&lt;p&gt;Download the lastest &lt;a href="http://www.pdflib.com/products/pdflib/download-source.html"&gt;tarball&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Extract the source&lt;br /&gt;&lt;br /&gt;&lt;code&gt;src&gt; tar zxf PDFlib-Lite-6.0.3.tar.gz&lt;/code&gt;&lt;br /&gt;&lt;code&gt;src&gt; cd PDFlib-Lite-6.0.3&lt;/code&gt;&lt;/p&gt;&lt;br /&gt; 
&lt;p&gt;If using 6.0.3, download this &lt;a href="http://www.railtie.net/configure.in.diff"&gt;patch&lt;/a&gt; to the root of your extracted PDFlib-Lite source, apply the patch, and regenerate the configure script &lt;br /&gt;&lt;br /&gt;&lt;code&gt;PDFlib-Lite-6.0.3&gt; patch -p0 &lt; configure.in.diff&lt;/code&gt;&lt;br /&gt;&lt;code&gt;PDFlib-Lite-6.0.3&gt; autoconf&lt;/code&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;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.&lt;br /&gt;&lt;br /&gt;
&lt;code&gt;On linux:&lt;br /&gt;PDFlib-Lite-6.0.3&gt; ./configure --with-ruby=/usr/bin/ruby --with-rubyincl=/usr/lib/ruby/1.8/i686-linux&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;On MacOSX (you built your own Ruby right?):&lt;br /&gt;
PDFlib-Lite-6.0.3&gt; ./configure --with-ruby=/usr/local/bin/ruby --with-rubyincl=/usr/local/lib/ruby/1.8/i686-darwin8.5.2&lt;/code&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;If you followed these instructions, the configure script should tell you that the Ruby bindings are active.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;Ruby language binding for PDFlib:       yes&lt;/code&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Build the library, (the 'make test' is required for these instructions to work)&lt;br /&gt;&lt;br /&gt;
&lt;code&gt;PDFlib-Lite-6.0.3&gt; make&lt;br /&gt;
PDFlib-Lite-6.0.3&gt; make test&lt;br /&gt;
PDFlib-Lite-6.0.3&gt; make install&lt;/code&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;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/&lt;rubyversion&gt; directory. Optionally, you can symlink the real library found in your /usr/lib or /usr/local/lib directory.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;PDFlib-Lite-6.0.3&gt; cd bind/pdflib/ruby
&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;On linux:&lt;br /&gt;PDFlib-Lite-6.0.3/bind/pdflib/ruby&gt; cp PDFlib.so /usr/lib/ruby/site_ruby/1.8&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;On MacOSX:&lt;br /&gt;
PDFlib-Lite-6.0.3/bind/pdflib/ruby&gt; cp PDFlib.bundle /usr/local/lib/ruby/site_ruby/1.8&lt;/code&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;
&lt;p&gt;We'll cover usage of PDFlib in part II of this article which should be complete in a week or so.&lt;/p&gt;</description>
      <pubDate>Sun, 02 Apr 2006 07:16:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:38ac18e964d73930ceb3fcf0bfdc789f</guid>
      <author>Bob Silva</author>
      <link>http://i.nfectio.us/articles/2006/04/02/generating-pdf-documents-with-rails-and-pdflib-part-i</link>
      <category>Ruby on Rails</category>
    </item>
  </channel>
</rss>
