Printing with Barby gem - barcode image is fuzzy
Asked Answered
A

1

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.

Adder answered 3/5, 2016 at 22:39 Comment(3)
I get this after running the above code: i.imgur.com/KRRKHHE.png Looks okay to me. You could try doubling the xdim and height?Compliancy
@Compliancy 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.Adder
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?Bhakti
A
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.

Adder answered 8/5, 2016 at 23:38 Comment(3)
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.Atlante
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.Mumford
please mark this as accepted answer if it solves the problem. Otherwise, people come here to help but cannot.Uella

© 2022 - 2024 — McMap. All rights reserved.