Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to create a GS1 128 barcode in Ruby on Rails is by using the "barby" gem. Here's an example code snippet to generate a GS1 128 barcode with the "barby" gem:

require 'barby/barcode/gs1_128'
require 'barby/outputter/png_outputter'

# Create the barcode object
barcode = Barby::GS1128.new('01012345678901234567')

# Set the application identifier for the barcode
barcode.application_identifier = '01'

# Generate the barcode image
png = Barby::PngOutputter.new(barcode).to_png

# Save the barcode image to a file
File.open('gs1_128.png', 'wb') { |f| f.write png }

In the above example, we create a new Barby::GS1128 barcode object with a sample data value of "01012345678901234567". We then set the application identifier to "01" to indicate that this is a GS1 128 barcode with a Global Trade Item Number (GTIN). Finally, we generate a PNG image of the barcode and save it to a file named "gs1_128.png".