toretore / barby

The Ruby barcode generator
http://toretore.github.com/barby/
MIT License
846 stars 171 forks source link

Switch type error #41

Closed lewispb closed 9 years ago

lewispb commented 9 years ago

Hi, I'm trying to switch type from B to C when creating a barcode. I've tried you're example code but get an error:

Barby::Code128A.new("ABC123\306def\3074567")

ArgumentError: invalid byte sequence in UTF-8

Could you please advise?

Thanks

toretore commented 9 years ago

you need to use ascii, not utf8:

"ABC123\306def\3074567".force_encoding('binary')

On Wed, Jan 28, 2015 at 1:07 PM, Lewis Buckley notifications@github.com wrote:

Hi, I'm trying to switch type from B to C when creating a barcode. I've tried you're example code but get an error:

Barby::Code128A.new("ABC123\306def\3074567")

ArgumentError: invalid byte sequence in UTF-8

Could you please advise?

Thanks

— Reply to this email directly or view it on GitHub https://github.com/toretore/barby/issues/41.

lewispb commented 9 years ago

Thanks for your quick reply. That works fine. When I use this data though:

Barby::Code128A.new("\3072\306lgbrg\30761\306wg\30746000000".force_encoding('binary'))

What I'm trying to do is a form of length optimization. Do you know of any libraries or similar that would help with this? Thanks again.

lewispb commented 9 years ago

Never mind, I've got it, found an issue that refers to this :) Would you like me to tidy up the github readme, maybe using Markdown?

toretore commented 9 years ago

Barby will automatically choose the most compact charset combination for you if you don't explicitly give one:

Barby::Code128.new('2lgbrg61wg46000000').full_data_with_change_codes => "2lgbrg61wg\xC746000000"