8

Anyone using the Barby gem ( https://github.com/toretore/barby ) to generate and print barcodes? I'm generating and printing png barcode files and they are coming out fuzzy. Note that the generated PNG files look great, even when zooming way in on the bars, yet when it's printed the edges are fuzzy. I'm printing barcodes of the same size and format I got elsewhere on the same printer and they look nice and crisp.

Here's the code I'm using in case anyone has any ideas how I can get it to look better. It's unusable as of now, as the scanner can't read it.

I noticed the created png has 72 dpi, and there seems to be no way to make it higher. That may or may not have something to do with it.

  require 'barby'
  require 'barby/barcode/code_128'
  require 'barby/outputter/png_outputter'

  fnsku            = 'ABC123'
  barcode          = Barby::Code128A.new(fnsku)
  outputter        = Barby::PngOutputter.new(barcode)

  outputter.height = 50
  outputter.xdim   = 1

  filepath    = 'barcode.png'
  File.open(filepath, 'w'){ |f| f.write outputter.to_png }

Thanks in advance.

99miles
  • 10,942
  • 18
  • 78
  • 123
  • I get this after running the above code: http://i.imgur.com/KRRKHHE.png Looks okay to me. You could try doubling the xdim and height? – ghr May 06 '16 at 21:29
  • @ghr Yep, the generated png files look great to me too, even when zooming way in on the bars. Yet, if you print it you'll see the edges are fuzzy, which is the issue I'm struggling with. It doesn't make sense. – 99miles May 06 '16 at 22:13
  • If you've figured out how to make larger barcodes by adjusting the xdim and height, i think the gem is doing its purpose. Have you tried converting the png to a different format before printing? Are you sure it's not a problem with your printer? – max pleaner May 08 '16 at 22:44

1 Answers1

0

The issue turned out to be in the PNG outputter. The solution was to write straight to PDF.

Not sure why the PNG outputter didn't cut it.

99miles
  • 10,942
  • 18
  • 78
  • 123
  • 1
    Is this your answer? You should mark it as such. My guess (wild) is that it's storing the barcode as a vector on the PDF. – Leonel Galán May 12 '16 at 16:06
  • Pretty much agree with @Leito. It sounds like you were changing the scale or *ratio* of the PNG image. Outputting to PDF allowed your printing step to avoid the scaling. Would also explain why the PNG looks fine before printing. – Cody Allan Taylor May 13 '16 at 18:01
  • please mark this as accepted answer if it solves the problem. Otherwise, people come here to help but cannot. – kronn Jul 01 '16 at 08:10