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 Perl

With our new command line tool CLIBar, making barcodes using Perl is a matter of seconds. The tool creates all common linear and 2D area barcode symbologies. Invoke to tool over the command line or Perl's system() call, set parameters of the barcode creation with an extra options file for highest flexibility. Suitable for individual barcodes, this solution shines when you have to mass create serial barcodes.

Sample Perl code to create consecutive barcodes with serial numbers (...67890, ...67891, ...67892 and so on):

$cmd_base = "/usr/local/bin/clibar";
$file_base = "-o./output_";
$extension = ".png";
$data_base = "-d40123456789";
$options = " -f./options.txt";

for($number = 0;$number < 10;$number++)
{
    $file = $file_base . $number . $extension;
    $data = $data_base . $number;
    @cmd = ($cmd_base, $file, $data, $options);
    system(@cmd);
}


Sample for Mac OS X, for Windows paths etc. may have to be adapted. The created bar codes are written as a raster image (PNG, TIFFs are also supported) to the output directory. Via the options file the barcode symbology, size, output resolution can be controlled. For different purposes you can maintain a multitude of option files, each one with the correct parameters for the task at hand.

A straight forward extension of the above sample would get the data from a plain text file or a database. A good approach if personnel or or product data had to be encoded in the barcode.

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 Perl, Perl, 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.