flag german flag uk flag us Tip: Bookmark this page with Ctrl-D (Win) or Apple-D (Mac) MainProductsKnow How / FAQStoreContact

How to create Barcodes with Ruby

With our new command line tool CLIBar, you can make barcodes the "Ruby Way". Create all common linear and 2D area barcode symbologies over the command line or from a script, control parameters of the barcode creation with an extra options file. This solution shines when you have to mass create serial barcodes but can also used with individual barcodes.

Sample Ruby code to create ten consecutive EAN barcodes:

cmd_base = "clibar -o";
file_base = "-./output_";
extension = ".png";
data_base = "-d 40123456789";
options = " -f. /options.txt";

for number in 0..9
    cmd = cmd_base + file_base + number.to_s + extension + data_base + number.to_s + options
    system(cmd)
end


Sample for Mac OS X, for Windows paths etc. may have to be adapted. The created bar codes are written as a raster PNG image (TIFF format also supported) to the target directory. By modifying the options file the desired barcode symbology, size, and output resolution can be controlled.

To encode personnel or product data in the barcode, you could easily extend the sample to pull data from a flat text file or a database.

The CLIBar Software is available for Mac OS X and Windows:

CLIBar Barcode Command Line Tool Mac
CLIBar Barcode Command Line Windows

Software comes with sample scripts for barcode creation in Ruby, Ruby, Ruby and AppleScript (Mac only). For small numbers of codes the tool can also be invoked directly from the command line or the Terminal.

Back to the main FAQ index.