Barcode Command Line Scripting Examples

Using Barcode’s capability to execute with command line parameters opens up a wide range of automation jobs. The complete list of command line parameters can be found at the command line parameters page. Let’s take a look at some typical examples:

Simple rendering to a vector file

Here’s how to render a vector file for EAN-13 barcode based on the specified data.

"C:\Program Files\Appsforlife\Barcode\Barcode.exe" --symbology=EAN-13  --data=123456789012 --output=ean13.eps

We use the following command line parameters here: “–symbology” tells Barcode to generate EAN-13 barcode. “–data” provides data for the barcode “–output” specifies the file to write the barcopde image to

That was pretty obvious and self-explanatory. Let’s take a look at another example:

Simple rendering to a raster file

"C:\Program Files\Appsforlife\Barcode\Barcode.exe" --symbology=EAN-13  --data=123456789012 --addon=12345 --output=ean13.png

This one also uses the addon parameter and specifies raster output instead.

Barcode command line execution also works as batch processing. Here is how you can render a huge load of barcodes using command line execution.

Batch rendering

Say we want to generate a number of barcodes and we have a file of barcode data named “data.txt”:

123456789012
123456789013
123456789014
123456789015
123456789016
123456789017

Here’s how to generate barcodes in batch mode:

"C:\Program Files\Appsforlife\Barcode\Barcode.exe" --symbology=ean-13 --source=data.txt --batch-output-separate --output=C:\Output\barcode.png

This way Barcode Software will export all the barcodes from the text file to the output folder in PNG format with prefix “barcode”, extended by the barcode texts.

Another option is to export them to a single PDF file:

"C:\Program Files\Appsforlife\Barcode\Barcode.exe" --symbology=ean-13 --source=data.txt --output=C:\Output\barcode.pdf

With this command line, you’ll get a single PDF file with all the barcodes.

In both cases Barcode Software will use the settings defined in the barcode “ean-13” that is passed to “–symbology” parameter. If you need a custom look of barcodes or custom PDF layout, you need to make a new barcode symbol in the software and configure it the way you need, first.

Another way of doing the same, is to loop through the data manually and call Barcode Software for each line of data. Put the text below into a new file named “run.cmd”:

for /f %%i in (data.txt) do (
    "C:\Program Files\Appsforlife\Barcode\Barcode.exe" --symbology=ean-13 --data=%%i --output=%%i.png
) 

You can create such script in any text editor, like Notepad, and save it wherever is convenient. When we run this script, the program will be executed for each line of the “data.txt” file, and will render a corresponding PNG file.

Scripting on Mac

The Mac-version of Barcode can be also scripted the same way:

/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=EAN-13 --data=1234567 --output=result.png

The batch rendering is pretty much the same:

/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=ean-13 --source=data.txt --batch-output-separate --output=/Output/barcode.png

Same for a single PDF file:

/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=ean-13 --source=data.txt --output=/Output/barcode.pdf

And the same for scripting. The batch rendering script is quite similar. Create a “batch.sh” with the content like this:

#!/bin/bash

while read code; do
    echo "Processing ${code}"
    /Applications/Barcode.app/Contents/MacOS/Barcode --symbology=EAN-13 --data=$code --output=$code.png
done < data.txt

Run the Terminal application and type the following command (make sure you run it from the same folder where the data.txt is located):

bash batch.sh   

Then make sure it runs through all the lines in your file and renders all the barcodes.