Barby 0.1 - Ruby barcode generator that doesn't suck (that much)

This is something I released a while ago, but I thought I’d announce
it here too, as I’m sure not everyone in the target group reads my
blog.

Barby is a pure Ruby barcode generator. It doesn’t rely on 3rd party
libraries (well, unless you want it to do anything useful) and it’s
easily extensible. It currently supports the following symbologies:

  • Code128
  • GS1128 (aka EAN/UCC-128)
  • EAN-13 (aka UPC-A)
    • Bookland
    • EAN-8
  • Code39

The logic for generating graphical representations of the barcodes is
split into “outputters”. There are currently two outputters, one that
uses RMagick and another that annotates a PDF/Writer document, and
creating new ones is easy.

Some sample code:

require ‘barby’
require ‘barby/outputter/rmagick_outputter’

barcode = Barby::Code128B.new(‘IM-IN-UR-BARCODE’)

File.open(‘test.png’, ‘w’) do |f|
f.write barcode.to_png
end

Barby is available as a gem (gem install barby) and from

If you feel like adding support for more symbologies, let me know and
I’ll put it into the “official” repo. If you spec it too, that’s
doubly awesome.

On Tue, Apr 22, 2008 at 4:05 AM, Tore D. [email protected]
wrote:

barcode = Barby::Code128B.new(‘IM-IN-UR-BARCODE’)
File.open(‘test.png’, ‘w’) do |f|
f.write barcode.to_png
end

Heh… I just showed this to a work associate of mine who has been
writing barcodes out directly to an epson printer comm spec.

He almost fell over in shock.

I love Ruby :slight_smile:

By the way:

baci:~ mikel$ date
Tue Apr 22 20:12:57 EST 2008
baci:~ mikel$ sudo gem install barby
Password:
ERROR: could not find barby locally or in a repository

Maybe still flowing into the gem servers?

Mikel

On Apr 22, 12:13 pm, Mikel L. [email protected] wrote:

Maybe still flowing into the gem servers?

Mikel

Hm, it’s a while now since I uploaded it to RF, so it should work.
This is my first gem on RF, so I might not have done everything right,
but it works for me now, and has before too… Hopefully (or, hopefully
not, probably) it’s just some sort of server hickup.

The gem file is here:
http://rubyforge.org/frs/?group_id=5831&release_id=20294

Tore

Does it work with PDF ??? how ??

I try to run this

require ‘barby’
require ‘barby/outputter/rmagick_outputter’

barcode = Barby::Code128B.new(‘IM-IN-UR-BARCODE’)

File.open(‘test.png’, ‘w’) do |f|
f.write barcode.to_png
end

but ruby says me that
barby.rb:8: uninitialized constant Barby::Code128B (NameError)
what I doing wrong??

Tore D. wrote:

On Apr 22, 12:13 pm, Mikel L. [email protected] wrote:

Maybe still flowing into the gem servers?

Mikel

Hm, it’s a while now since I uploaded it to RF, so it should work.
This is my first gem on RF, so I might not have done everything right,
but it works for me now, and has before too… Hopefully (or, hopefully
not, probably) it’s just some sort of server hickup.

The gem file is here:
http://rubyforge.org/frs/?group_id=5831&release_id=20294

Tore

Please somebody can help me , I’m new with ruby , can anybdy tell me
how use barby with PDF’s documents ?

Thanks

Foreero I. wrote:

Please somebody can help me , I’m new with ruby , can anybdy tell me
how use barby with PDF’s documents ?

It’s not the only way, but if you’re using Ruby FPDF, I’ve written a
small extension that can print Barby codes into FPDF-generated PDFs:

http://rca.vmk.zhdk.ch/blog/software/

Or straight in svn:

http://code.zhdk.ch/svn/leihs/trunk/lib/fpdf/fpdf_barby.rb

The next feature I’ll add is that you can specify the maximum width of
barcodes, as some applications apparently require this.

The code is not very Rubyish as you’ll see, but we can’t really help it.
With Ruby FPDF we’re stuck in a world where Ruby speaks PHP, so which
way around should an FPDF extension think? This one is messed up in its
head and tries to do both, with variables in all sorts of casings. I’ll
have to clean that up. Also, some more error handling would be nice.

We’ll be starting to use this in production with several ten thousand
barcodes in Code 128A and Code 39, because we soon need to put together
a batch labeling feature for our inventory system, so I’m sure it’ll
improve a bit then :slight_smile:

Let me know how and if it works for you, against all odds.

Ramon

On Jun 13, 8:15 am, Ramon C. [email protected] wrote:

Foreero I. wrote:

Please somebody can help me , I’m new with ruby , can anybdy tell me
how use barby with PDF’s documents ?

It’s not the only way, but if you’re using Ruby FPDF, I’ve written a
small extension that can print Barby codes into FPDF-generated PDFs:

Also, if you’re using PDF::Writer, there’s built-in support for that:

require ‘barby’
require ‘barby/outputter/pdfwriter_outputter’

pdf = PDF::Writer.new
barcode = Barby::Code128B.new(‘humbaba’)
barcode.annotate_pdf(pdf)

The CairoOutputter can generate PDFs from scratch if you for some
reason want that:

require ‘barby/outputter/cairo_outputter’

File.open(‘test.pdf’){|f| f << barcode.to_pdf }

In the git repo there’s an experimental PrawnOutputter that can both
annotate and generate PDFs using Prawn.

Tore

Hate to resurrect an old thread, but I got this to work with Prawn, and
it’s
pretty slick.
(This is in a prawnto/Rails view)

require ‘barby’
require ‘barby/outputter/prawn_outputter’

pdf.bounding_box [450,700], :width => 100 do
barcode = Barby::Code39.new(@order.order_identifier)
barcode.annotate_pdf(pdf, :height => 30)
end

Plops a nice vector barcode right there. Really slick!

Kevin

To whoever wrote this application/extension, I’d like to express my
gratitude. I’m facing an issue where barcodes could be the solution…
especially how these barcodes can be outputted to PDF is hopeful to me,
so I’m looking forward putting it to the test… anyway, without your
collective efforts, I’d had little to test, so thanks a bunch.

Regards,
A.

On Tue, Apr 22, 2008 at 2:05 AM, Tore D. [email protected]
wrote:

This is something I released a while ago, but I thought I’d announce

Hi, you mentioned a ver 0.1 but we got a ver0.4.2. Are they the same
gem?

thanks for barby (very nice name btw)
best regards -botp