Gbarcode Support for Ruby FPDF

I was going mad fixing a bug in a very convoluted barcode printing feature in the equipment management system we’re developing. After a while I gave up — we must have triggered something deep within Rails or Ruby, and it wasn’t going to go away soon. The details are complicated and boring, but just know this: Instead of fixing the bug, I completely rewrote our barcode handling and as a side effect developed an extension for Ruby FPDF to support Gbarcode 🙂

Please give it a try if you need barcode support in your PDFs and let me know what you want to improve and what fails horribly for you.

I wanted to send it to Brian Ollenberger to see if he likes it and would like to include it with Ruby FPDF, but his website appears to be down. Anyhow, I would have to clean things up and make it all elegant and sexxay first.

Still, standing on the shoulders of giants is just the beginning. With a dozen lines of code I managed to tie Gbarcode into Ruby, and through that into Rails, and I’m not even a good coder. Free Software rocks! Well, okay, FPDF isn’t technically Free Software, but still. All of this just feels very good, and it gives me a kind of productivity I could only dream of with proprietary software and complicated licenses. I had the whole thing hacked together in less than an hour.

2 thoughts on “Gbarcode Support for Ruby FPDF”

  1. Author of GBarcode here, curious as to why you didn’t just embed the produced gbarcode’s output to EPS, and embed that file into the PDF using the fpdf_eps.rb functionality?

    Like

  2. I did try that, but the EPS function in the FPDF_EPS extension choked on the EPS that came out of Gbarcode. I poked around a bit but don’t know raw PDF or EPS enough to find out what’s wrong. It usually was OK with the first few lines of the EPS but died later on — if I find the time, I can perhaps reproduce the error.

    A second problem was that in a RoR environment, dealing with pipes to read the EPS content into a variable would often lead to unexplainable I/O errors. Sometimes it worked for hours, then it failed on every fifth try, perhaps on the seventh, then it worked again. We spent a day trying to locate the error but couldn’t really figure it out.

    I thought a solution that is completely PDF and in-memory would be quite sexy, and since Gbarcode offers access to the widths of the barcode, it’s quite trivial to implement. We needed a solution fast, and this seems to work elegantly. The barcode problem will come up again for us in a few months though, if I’m allowed to work on it some more, it would definitely make sense to work out the FPDF_EPS issues. I can’t guess whether they are in the generated EPS or in the extension.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s