Command Line Barcode Generation

Barcode can be used from 3rd party applications or scripts to generate barcodes in command line mode. The only thing you need is to configure the barcode appearance first and then you can use it as a template for generating barcodes. In this tutorial we assume that you have a barcode named “EAN-13” configured in the barcodes list. If not, you need to do it first or use a different barcode name in the code examples below.

Simple Barcode Generation

Barcode expects to see some command line parameters to switch to the command line mode. These parameters are --symbology, --data and --output. All three need to be specified, as otherwise Barcode will start in the standard, visual mode.

Here is the simplest command line example for Mac:

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

A similar line for Windows is:

"C:\Program Files\Appsforlife\Barcode\barcode.com" --symbology=EAN-13 --data=1234567890128 --output=result.png

This makes a PNG file with the barcode design you configured and the data you provided. You can use other file types, like PDF, EPS, TIFF or TIF. The latter is the monochrome one.

Addon Processing

For EAN-13, ISBN-13 and UPC-A barcodes you can specify addon using a semicolon in the --data parameter this way:

--data=1234567890128;12345

This gives you a barcode with main text set to “12345678901238” and the addon set to “12345”.

For ISBN-13 barcodes you specify the price in decimal format like this:

--data=978123456789;10.20

Which makes an addon “51020” if the barcode is configured to use the US pricing mode.

Custom Text Variables

You can control custom text variables this way:

--var=var1=Hello --var=var2="Some more text here"

You can have as many --var=<var>=<value> declarations as needed. Use quotation marks if values or variables contain spaces. Note that you might need to “escape” the quotation marks in some environments:

--var=var1=\"Some more text\"

This depends on the operating system and batch processor (shell) you use.

Batch Command Line Barcode Generation

You can generate barcodes in bulk by using a CSV or Excel (XLSX) file as data source. The simplest way is to start with a plain text file like below, where each line represents a single barcode:

123456789012;12345
234567890121;51234
345678901212;45123
456789012123;34512
567890121234;23451
678901212345;12345

Save it as “data.txt”, then you can do this from the folder of that file:

# Mac
/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=EAN-13 --source=data.txt --output=result.png

# Windows
"C:\Program Files\Appsforlife\Barcode\barcode.com" --symbology=EAN-13 --source=data.txt --output=result.png

The difference is that the --data parameter is replaced with the --source parameter which points to the text file with barcodes.

After you run the line above, you’ll get a set of files named this way:

result123456789012_12345.png
result234567890121_51234.png
result345678901212_45123.png
result456789012123_34512.png
result567890121234_23451.png
result678901212345_12345.png

As you may see, Barcode used the --output parameter you provided to get a prefix and extension for the generated files. The rest of the name is made of the barcode data provided in the text file.

Using Real CSV Files

The file above is actually a CSV file, it just contains no header line. Barcode tries to detect the header line by looking for a column named “Data” and if it cannot find one, it considers the first column as “Data” and the second one as “Addon”. You can specify everything yourself this way:

Addon;Data
12345;123456789012
51234;234567890121
45123;345678901212
34512;456789012123
23451;567890121234
12345;678901212345

Here we specified the column names in the first line and changed the columns order simply because we can. You can re–save this file as “data.txt” like above or name it more specifically as “data.csv” to emphasize that it is a “comma–separated values” format.

Then you can run it the same way:

# Mac
/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=EAN-13 --source=data.csv --output=result.png

# Windows
"C:\Program Files\Appsforlife\Barcode\barcode.com" --symbology=EAN-13 --source=data.csv --output=result.png

The result will be the same as above, as this time the software will use the first line of the text file as column names and get the data and addon parts of the barcode from proper columns.

Barcode supports commas, semicolons, colons or tabs as value separators in CSV files and tries to automatically detect the proper format. If something doesn’t work, try using a different separator or Excel format instead. You can also contact us for help with your file.

Using More Columns

There is a few “reserved” column names that are processed a special way by Barcode:

You can make more columns in the source CSV file and use them for custom text variables. Here is an example:

Data;Addon;Information
123456789012;12345;Text 1
234567890121;51234;Text 2
345678901212;45123;Text 3
456789012123;34512;Text 4
567890121234;23451;Text 5
678901212345;12345;Text 6

Now if you make a custom text field and use {information} variable there, it will be replaced with the third column of the file listed above.

You can have as many extra columns for custom text variables, as needed.

A Column With File Names

You can name output files using one of the source file columns. To do so make a source file having a dedicated column with file names:

Data;Addon;Information;Filename
123456789012;12345;Text 1;Product 0001
234567890121;51234;Text 2;Product 0002
345678901212;45123;Text 3;Product 0003
456789012123;34512;Text 4;Product 0004
567890121234;23451;Text 5;Product 0005
678901212345;12345;Text 6;Product 0006

And then use the extra --output-column=Filename parameter when running Barcode:

# Mac
/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=EAN-13 --source=data.csv --output-column=Filename --output=result.png

# Windows
"C:\Program Files\Appsforlife\Barcode\barcode.com" --symbology=EAN-13 --source=data.csv --output-colum=Filename --output=result.png

Barcode will use both the Filename column and the --output parameter to name files, so you will end up with names like “resultProduct 0001.png”. If you want to name files exactly using the column data, you can change the --output parameter this way:

# Mac
/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=EAN-13 --source=data.csv --output-column=Filename --output=.png

# Windows
"C:\Program Files\Appsforlife\Barcode\barcode.com" --symbology=EAN-13 --source=data.csv --output-colum=Filename --output=.png

By specifying an empty name in the “output” parameter you tell Barcode to use the column data for output files naming.

See below for more information on the “output” parameter processing.

Using Excel Files

Barcode can read Excel files (in XLSX format) exactly as it reads CSV files. Everything above applies to Excel files, as well.

Naming Files Using Counter

You can configure Barcode to name the output files using a counter this way:

# Mac
/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=EAN-13 --source=data.csv --mode=counter --counter-from=100 --output=result.png

# Windows
"C:\Program Files\Appsforlife\Barcode\barcode.com" --symbology=EAN-13 --source=data.csv --mode=counter --counter-from=100 --output=result.png

Note the two parameters added: --mode=counter, which enables the using of counter for naming, and the optional --counter-from=100 which sets the first number to use for the counter. After running the line above for the same source file, you’ll get these files:

result100.png
result101.png
result102.png
result103.png
result104.png
result105.png
result106.png

This is pretty much the same, as you configure it in the visual mode. Although Barcode remembers what type of generation you used the last time, it doesn’t use that information for command line processing to make it more predictable.

Processing The “Output” Parameter

When barcodes are generated in bulk, the software needs to name the output files and place them somewhere. In order to do that it uses the information about current barcode and the --output parameter you specified.

Depending on the batch generation mode, the barcode information could be:

The software takes this information as a “base” barcode name and then checks what is passed in the --output parameter. The format of the parameter is below:

--output=<path>/<file>.<ext>

So you can specify a relative path, a file name and extension. Barcode uses the path you provided (it is optional) to output files to a different folder. It uses the extension you provided to determine the output file format and finally it uses the “file” part of the parameter as a prefix to the “base” barcode name it already has (see above).

For instance if the base barcode name is taken from a data column and is “Product 0001”, and the “output” parameter is specified this way:

--output=tmp/file.pdf

Barcode will do this:

  1. It splits the “output” parameter to path (“tmp”), file name (“file”) and extension (“pdf”);
  2. It takes the base name (“Product 0001”) and puts the file name (“file”) in front, getting “fileProduct 0001”;
  3. It goes to the path (“tmp”) subfolder and saves the barcode in PDF format (as defined by the extension), naming it as “fileProduct 0001.pdf”.

If you specify the “output” parameter as --output=tmp/.pdf, there will be no file name and the file will be named as “Product 0001.pdf” in the “tmp” folder.

Single File Batch Generation

You can also output barcodes to a single file this way on Mac:

/Applications/Barcode.app/Contents/MacOS/Barcode --symbology=EAN-13 --source=data.txt --mode=single --output=result.pdf

On Windows:

"C:\Program Files\Appsforlife\Barcode\barcode.com" --symbology=EAN-13 --source=data.txt --mode=single --output=result.pdf

The command lines parameters are pretty much the same as shown above for multiple file output, but this time we used --mode=single parameter, which tells Barcode to output everything to the same file. The output file should have a PDF extension, as only this one is supported by the software.

Running the line above should give you a PDF file with all the barcodes you listed in the text file. Barcode will use the grid settings you configured when you last time used the batch processing in visual mode for this generator. It is the same as with the visual appearance: you first configure it with the user interface, then you can use it from the command line.

You can use simple text, CSV or Excel files in this mode exactly as in the multiple–files output mode.

Before You Start

Note that almost all the batch generation features mentioned above can be done in the application itself with just a few mouse clicks.

Even if you want to automate barcode generation and need to use the command line mode for sure, it is highly recommended to try the visual way first. You will see how it works, you will see how the software reads and process the data files and how it names the output ones. Once everything is running smooth in the app, you can repeat the same with command line parameters, if needed.

Also, if something goes wrong with the command line mode, try doing the same in visual mode and see where the problem is. Once solved, you can return to the command line mode.

Batch Barcode Generation With Scripting

Finally, if the above is not enough you can always use a scripting language of your operating system to process the source file and use the Barcode software to generate one barcode at a time. Here is a Mac example using the bash script:

#!/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

Same code for Windows is below:

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

In both cases we use the scripting language to read the text file line by line and call Barcode to generate images for us. This way you get more flexibility with the file naming and symbology selection.

More Barcode Tutorials

Installation

Basics

EAN Barcodes

UPC Barcodes

NDC Barcodes

QR Code

Other Barcodes

Export

Automation

Other