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, and I ended up rewriting our barcode handling. 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.
0 thoughts on “Gbarcode Support for Ruby FPDF”
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?
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.