Zint Barcode Generator and Zint Barcode Studio User Manual

4 Using the Command Line

On this page

4. Using the Command Line

This section describes how to encode data using the command line frontend (CLI) program. The examples given are for the Unix platform, but the same options are available for Windows - just remember to include the executable file extension if ".EXE" is not in your PATHEXT environment variable, i.e.:

zint.exe -d "This Text"

For compatibility with Windows the examples use double quotes to delimit data, though on Unix single quotes are generally preferable as they stop the shell from processing any characters such as backslash or dollar. A single quote itself is dealt with by terminating the single-quoted text, backslashing the single quote, and then continuing:

zint -d 'Text containing a single quote '\'' in the middle'

Some examples use backslash (\) to continue commands onto the next line. For Windows, use caret (^) instead.

Certain options that take values have short names as well as long ones, namely -b (--barcode), -d (--data), -i (--input), -o (--output) and -w (--whitesp). For these a space should be used to separate the short name from its value, to avoid ambiguity. For long names a space or an equals sign may be used. For instance:

zint -d "This Text"
zint --data="This Text"
zint --data "This Text"

The examples use a space separator for short option names, and an equals sign for long option names.

4.1 Inputting Data

The data to encode can be entered at the command line using the -d or --data option, for example

zint -d "This Text"

This will encode the text "This Text". Zint will use the default symbology, Code 128, and output to the default file "out.png" in the current directory. Alternatively, if libpng was not present when Zint was built, the default output file will be "out.gif".

The data input to the Zint CLI is assumed to be encoded in UTF-8 (Unicode) format (Zint will correctly handle UTF-8 data on Windows). If you are encoding characters beyond the 7-bit ASCII set using a scheme other than UTF-8 then you will need to set the appropriate input options as shown in 4.11 Input Modes below.

Non-printing characters can be entered on the command line using backslash (\) as an escape character in combination with the --esc switch. Permissible sequences are shown in the table below.

Table 2: Escape Sequences
Escape SequenceASCII EquivalentNameInterpretation
\00x00NULNull character
\E0x04EOTEnd of Transmission
\a0x07BELBell
\b0x08BSBackspace
\t0x09HTHorizontal Tab
\n0x0ALFLine Feed
\v0x0BVTVertical Tab
\f0x0CFFForm Feed
\r0x0DCRCarriage Return
\L0x10DLEData Link Escape
\e0x1BESCEscape
\F0x1CFSFile Separator
\G0x1DGSGroup Separator
\R0x1ERSRecord Separator
\N0x1FUSUnit Separator
\(0x28(Opening parenthesis (only with --gs1parens)
\)0x29)Closing parenthesis (only with --gs1parens)
\\0x5C\Backslash
\dNNNNNNAny 8-bit character where NNN is decimal (000-255)
\oNNN0oNNNAny 8-bit character where NNN is octal (000-377)
\xNN0xNNAny 8-bit character where NN is hexadecimal (00-FF)
\uNNNNAny 16-bit Unicode BMP3 character where NNNN is hexadecimal (0000-FFFF)
\UNNNNNNAny 21-bit Unicode character where NNNNNN is hexadecimal (000000-10FFFF)

Extra escape sequences are available for certain symbologies using the --extraesc option that allows the insertion of special characters or, in the case of Code 128 only, to manually switch Code Sets. Extra escapes begin with the sequence backslash caret (“\^”):

Table 3: Extra Escape Sequences
Extra Escape SequenceInterpretationAvailable for Symbology
\^1Insert FNC1 characterAztec Code, Code 128, Data Matrix
\^^Literal \^Aztec Code, Code 128, Data Matrix
\^A, \^B, \^CSelect Code Set A, B or C respectivelyCode 128 only
\^@Exit manual Code Set selection and resume automatic Code Set selectionCode 128 only

Currently the only special character recognised is the Function Code 1 character FNC1. If your data contains the sequence “\^” then it must be escaped using the extra escape sequence “\^^”, i.e. by doubling the caret.

See 6.1.10.1 Standard Code 128 (ISO 15417) for the details on manually switching Code Sets.

Input data can be read directly from file using the -i or --input switch as shown below. The input file is assumed to be UTF-8 formatted unless an alternative mode is selected. This option replaces the use of the -d switch.

zint -i somefile.txt

To read from stdin specify a single hyphen "-" as the input file.

Note that except when batch processing (see 4.12 Batch Processing below), the file (or stdin) should not end with a newline (LF on Unix, CR+LF on Windows) unless you want the newline to be encoded in the symbol.

4.2 Directing Output

Output can be directed to a file other than the default using the -o or --output switch. For example:

zint -o here.png -d "This Text"

This draws a Code 128 barcode in the file "here.png". If an Encapsulated PostScript file is needed simply append the filename with ".eps", and so on for the other supported file types:

zint -o there.eps -d "This Text"

The currently supported output file formats are:

Table 4: Output File Formats
ExtensionFile format
bmpWindows Bitmap
emfEnhanced Metafile Format
epsEncapsulated PostScript
gifGraphics Interchange Format
pcxZSoft Paintbrush image
pngPortable Network Graphic
svgScalable Vector Graphic
tifTagged Image File Format
txtText file (see 4.19 Other Options)

The filename can contain directories and sub-directories also, which will be created if they don’t already exist:

zint -o "dir/subdir/filename.eps" -d "This Text"

Note that on Windows, filenames are assumed to be UTF-8 encoded.

4.3 Selecting Barcode Type

Selecting which type of barcode you wish to produce (i.e. which symbology to use) can be done at the command line using the -b or --barcode switch followed by the appropriate integer value or name in the following table. For example to create a Data Matrix symbol you could use:

zint -b 71 -o datamatrix.png -d "Data to encode"

or

zint -b DATAMATRIX -o datamatrix.png -d "Data to encode"

Names are treated case-insensitively by the CLI, and the BARCODE_ prefix and any underscores are optional.

Table 5: Barcode Types (Symbologies)
Numeric ValueName4Barcode Name
1BARCODE_CODE11Code 11
2BARCODE_C25STANDARD *Standard Code 2 of 5
3BARCODE_C25INTERInterleaved 2 of 5
4BARCODE_C25IATACode 2 of 5 IATA
6BARCODE_C25LOGICCode 2 of 5 Data Logic
7BARCODE_C25INDCode 2 of 5 Industrial
8BARCODE_CODE39Code 3 of 9 (Code 39)
9BARCODE_EXCODE39Extended Code 3 of 9 (Code 39+)
10BARCODE_EAN8 †EAN-8 (European Article Number) GTIN-8
11BARCODE_EAN_2ADDON †EAN/UPC 2-digit add-on (standalone)
12BARCODE_EAN_5ADDON †EAN/UPC 5-digit add-on (standalone)
15BARCODE_EAN13 †EAN-13 (European Article Number) GTIN-13
16BARCODE_GS1_128 *GS1-128 (UCC.EAN-128)
18BARCODE_CODABARCodabar
20BARCODE_CODE128Code 128 (automatic Code Set switching)
21BARCODE_DPLEITDeutsche Post Leitcode
22BARCODE_DPIDENTDeutsche Post Identcode
23BARCODE_CODE16KCode 16K
24BARCODE_CODE49Code 49
25BARCODE_CODE93Code 93
28BARCODE_FLATFlattermarken
29BARCODE_DBAR_OMN *GS1 DataBar Omnidirectional (including GS1 DataBar Truncated)
30BARCODE_DBAR_LTD *GS1 DataBar Limited
31BARCODE_DBAR_EXP *GS1 DataBar Expanded
32BARCODE_TELEPENTelepen Alpha
34BARCODE_UPCAUPC-A
35BARCODE_UPCA_CHKUPC-A with check digit
37BARCODE_UPCEUPC-E
38BARCODE_UPCE_CHKUPC-E with check digit
40BARCODE_POSTNETPOSTNET
47BARCODE_MSI_PLESSEYMSI Plessey
49BARCODE_FIMFIM
50BARCODE_LOGMARSLOGMARS
51BARCODE_PHARMAPharmacode One-Track
52BARCODE_PZNPZN
53BARCODE_PHARMA_TWOPharmacode Two-Track
54BARCODE_CEPNETBrazilian CEPNet
55BARCODE_PDF417PDF417
56BARCODE_PDF417COMP *Compact PDF417 (Truncated PDF417)
57BARCODE_MAXICODEMaxiCode
58BARCODE_QRCODEQR Code
60BARCODE_CODE128ABCode 128 (Suppress Code Set C)
63BARCODE_AUSPOSTAustralia Post Standard Customer
66BARCODE_AUSREPLYAustralia Post Reply Paid
67BARCODE_AUSROUTEAustralia Post Routing
68BARCODE_AUSDIRECTAustralia Post Redirection
69BARCODE_ISBNXISBN (EAN-13 with verification stage)
70BARCODE_RM4SCCRoyal Mail 4-State Customer Code (RM4SCC)
71BARCODE_DATAMATRIXData Matrix (ECC 200)
72BARCODE_EAN14EAN-14
73BARCODE_VINVehicle Identification Number
74BARCODE_CODABLOCKFCodablock F
75BARCODE_NVE18NVE-18 (SSCC-18)
76BARCODE_JAPANPOSTJapanese Postal Code
77BARCODE_KOREAPOSTKorea Post
79BARCODE_DBAR_STK *GS1 DataBar Stacked
80BARCODE_DBAR_OMNSTK *GS1 DataBar Stacked Omnidirectional
81BARCODE_DBAR_EXPSTK *GS1 DataBar Expanded Stacked
82BARCODE_PLANETPLANET
84BARCODE_MICROPDF417MicroPDF417
85BARCODE_USPS_IMAIL *USPS Intelligent Mail (OneCode)
86BARCODE_PLESSEYUK Plessey
87BARCODE_TELEPEN_NUMTelepen Numeric
89BARCODE_ITF14ITF-14
90BARCODE_KIXDutch Post KIX Code
92BARCODE_AZTECAztec Code
93BARCODE_DAFTDAFT Code
96BARCODE_DPDDPD Code
97BARCODE_MICROQRMicro QR Code
98BARCODE_HIBC_128HIBC Code 128
99BARCODE_HIBC_39HIBC Code 39
102BARCODE_HIBC_DMHIBC Data Matrix
104BARCODE_HIBC_QRHIBC QR Code
106BARCODE_HIBC_PDFHIBC PDF417
108BARCODE_HIBC_MICPDFHIBC MicroPDF417
110BARCODE_HIBC_BLOCKFHIBC Codablock F
112BARCODE_HIBC_AZTECHIBC Aztec Code
115BARCODE_DOTCODEDotCode
116BARCODE_HANXINHan Xin (Chinese Sensible) Code
119BARCODE_MAILMARK_2DRoyal Mail 2D Mailmark (CMDM) (Data Matrix)
121BARCODE_MAILMARK_4SRoyal Mail 4-State Mailmark
128BARCODE_AZRUNEAztec Runes
129BARCODE_CODE32Code 32
131BARCODE_GS1_128_CC *GS1 Composite Symbol with GS1-128 linear component
132BARCODE_DBAR_OMN_CC *GS1 Composite Symbol with GS1 DataBar Omnidirectional linear component
133BARCODE_DBAR_LTD_CC *GS1 Composite Symbol with GS1 DataBar Limited linear component
134BARCODE_DBAR_EXP_CC *GS1 Composite Symbol with GS1 DataBar Expanded linear component
135BARCODE_UPCA_CCGS1 Composite Symbol with UPC-A linear component
136BARCODE_UPCE_CCGS1 Composite Symbol with UPC-E linear component
137BARCODE_DBAR_STK_CC *GS1 Composite Symbol with GS1 DataBar Stacked component
138BARCODE_DBAR_OMNSTK_CC *GS1 Composite Symbol with GS1 DataBar Stacked Omnidirectional component
139BARCODE_DBAR_EXPSTK_CC *GS1 Composite Symbol with GS1 DataBar Expanded Stacked component
140BARCODE_CHANNELChannel Code
141BARCODE_CODEONECode One
142BARCODE_GRIDMATRIXGrid Matrix
143BARCODE_UPNQRUPNQR (Univerzalnega Plačilnega Naloga QR Code)
144BARCODE_ULTRAUltracode
145BARCODE_RMQRRectangular Micro QR Code (rMQR)
146BARCODE_BC412IBM BC412 (SEMI T1-95)
147BARCODE_DXFILMEDGEDX Film Edge Barcode
148BARCODE_EAN8_CC †GS1 Composite symbol with EAN-8 linear component
149BARCODE_EAN13_CC †GS1 Composite symbol with EAN-13 linear component

4.4 Adjusting Height

The height of a symbol (except those with a fixed width-to-height ratio) can be adjusted using the --height switch. For example:

zint --height=100 -d "This Text"

This specifies a symbol height of 100 times the X-dimension of the symbol.

The default height of most linear barcodes is 50.0X, but this can be changed for barcodes whose specifications give a standard height by using the switch --compliantheight. For instance

zint -b LOGMARS -d "This Text" --compliantheight

will produce a barcode of height 45.455X instead of the normal default of 50.0X. The flag also causes Zint to return a warning if a non-compliant height is given:

zint -b LOGMARS -d "This Text" --compliantheight --height=6.2
Warning 247: Height not compliant with standards

Another switch is --heightperrow, which can be useful for symbologies that have a variable number of linear rows, namely Codablock F, Code 16K, Code 49, GS1 DataBar Expanded Stacked, MicroPDF417 and PDF417, as it changes the treatment of the height value from overall height to per-row height, allowing you to specify a consistent height for each linear row without having to know how many there are. For instance

zint -b PDF417 -d "This Text" --height=4 --heightperrow
zint -b PDF417 -d "This Text" --height=4 --heightperrow
Figure 14: zint -b PDF417 -d "This Text" --height=4 --heightperrow

will produce a barcode of height 32X, with each of the 8 rows 4X high.

4.5 Adjusting Whitespace

The amount of horizontal whitespace to the left and right of the generated barcode can be altered using the -w or --whitesp switch, in integral multiples of the X-dimension. For example:

zint -w 10 -d "This Text"

This specifies a whitespace width of 10 times the X-dimension of the symbol both to the left and to the right of the barcode.

The amount of vertical whitespace above and below the barcode can be altered using the --vwhitesp switch, in integral multiples of the X-dimension. For example for 3 times the X-dimension:

zint --vwhitesp=3 -d "This Text"

Note that the whitespace at the bottom appears below the text, if any.

Horizontal and vertical whitespace can of course be used together:

zint -b DATAMATRIX --whitesp=1 --vwhitesp=1 -d "This Text"

A --quietzones option is also available which adds quiet zones compliant with the symbology’s specification. This is in addition to any whitespace specified with the --whitesp or --vwhitesp switches.

Note that Codablock F, Code 16K, Code 49, ITF-14, EAN-13, EAN-8, EAN/UPC add-ons, ISBN, UPC-A and UPC-E have compliant quiet zones added by default. This can be disabled with the option --noquietzones.

4.6 Adding Boundary Bars and Boxes

Zint allows the symbol to be bound with ‘boundary bars’ (also known as ‘bearer bars’) using the option --bind. These bars help to prevent misreading of the symbol by corrupting a scan if the scanning beam strays off the top or bottom of the symbol. Zint can also put a border right around the symbol and its horizontal whitespace with the --box option.

The width of the boundary bars or box borders, in integral multiples of the X-dimension, must be specified using the --border switch. For example:

zint --box --border=10 -w 10 -d "This Text"
zint --border=10 --box -d "This Text" -w 10
Figure 15: zint --border=10 --box -d "This Text" -w 10

gives a box with a width 10 times the X-dimension of the symbol. Note that when specifying a box, horizontal whitespace is usually required in order to create a quiet zone between the barcode and the sides of the box. To add a boundary bar to the top only use --bindtop.

For linear symbols, horizontal boundary bars appear tight against the barcode, inside any vertical whitespace (or text). For matrix symbols, however, where they are decorative rather than functional, boundary bars appear outside any whitespace.

zint -b QRCODE --border=1 --box -d "This Text" --quietzones
Figure 16: zint -b QRCODE --border=1 --box -d "This Text" --quietzones

Codablock F, Code 16K and Code 49 always have boundary bars, and default to particular horizontal whitespace values. Special considerations apply to ITF-14 and DPD - see 6.1.2.6 ITF-14 and 6.1.10.7 DPD Code for those symbologies.

4.7 Using Colour

The default colours of a symbol are a black symbol on a white background. Zint allows you to change this. The -r or --reverse switch allows the default colours to be inverted so that a white symbol is shown on a black background (known as “reflectance reversal” or “reversed reflectance”). For example the command

zint -r -d "This Text"

gives an inverted Code 128 symbol. This is not practical for most symbologies but white-on-black is allowed by the Aztec Code, Data Matrix, DotCode, Han Xin Code, Grid Matrix and QR Code symbology specifications.

For more specific needs the foreground (ink) and background (paper) colours can be specified using the --fg and --bg options followed by a number in "RRGGBB" hexadecimal notation (the same system used in HTML) or in "C,M,Y,K" decimal percentages format (the latter normally used with the --cmyk option - see below). For example the command

zint --fg=00FF00 -d "This Text"

alters the symbol to a bright green.

zint -d "This Text" --fg=00FF00
Figure 17: zint -d "This Text" --fg=00FF00

Zint also supports RGBA colour information for those output file formats which support alpha channels (currently only GIF, PCX, PNG, SVG and TIF, with GIF supporting either a background or foreground alpha but not both) in a "RRGGBBAA" format. For example:

zint --fg=00ff0055 -d "This Text"
zint -d "This Text" --fg=00FF0055
Figure 18: zint -d "This Text" --fg=00FF0055

will produce a semi-transparent green foreground with a standard (white) background. Note that transparency is treated differently by raster and vector (SVG) output formats, as for vector output the background will “shine through” a transparent foreground. For instance

zint --bg=ff0000 --fg=ffffff00 ...

will give different results for PNG and SVG. Experimentation is advised!

In addition the --nobackground option will remove the background from all output formats except BMP.5

The --cmyk option is specific to output in Encapsulated PostScript (EPS) and TIF, and selects the CMYK colour space. Custom colours should then usually be given in the comma-separated "C,M,Y,K" format, where C, M, Y and K are expressed as decimal percentage values from 0 to 100. RGB values may still be used, in which case they will be converted formulaically to CMYK approximations.

4.8 Rotating the Symbol

The symbol can be rotated through four orientations using the --rotate option followed by the angle of rotation, valid values being 0 (the default), 90, 180 and 270.

zint -d "This Text" --rotate=90
Figure 19: zint -d "This Text" --rotate=90

4.9 Adjusting Image Size (X-dimension)

The size of the image can be altered using the --scale option, which sets the X-dimension. The default scale is 1.0.

The scale is multiplied by 2 (with the exception of MaxiCode) before being applied to the X-dimension. For MaxiCode, it is multiplied by 10 for raster output, by 40 for EMF vector output, and by 2 otherwise (non-EMF vector output).

For non-MaxiCode raster output, the default scale of 1 results in an X-dimension of 2 pixels. For example for non-MaxiCode PNG images a scale of 5 will increase the X-dimension to 10 pixels. For MaxiCode, see 4.9.3 MaxiCode Raster Scaling below.

Scales for non-MaxiCode raster output should be given in increments of 0.5, i.e. 0.5, 1, 1.5, 2, 2.5, 3, 3.5, etc., to avoid the X-dimension varying across the symbol due to interpolation. 0.5 increments are also faster to render.

The minimum scale for non-MaxiCode raster output in non-dotty mode is 0.5, giving a minimum X-dimension of 1 pixel. For MaxiCode, it is 0.2. The minimum scale for raster output in dotty mode is 1 (see 4.15 Working with Dots). For raster output, text will not be printed for scales less than 1.

The minimum scale for vector output is 0.1, giving a minimum X-dimension of 0.2 (or for MaxiCode EMF output, 4). The maximum scale for both raster and vector is 200.

To summarize the more intricate details:

Table 6: Scaling Multipliers and Minima
MaxiCode?OutputMultiplierMin. Scale (non-dotty)Min. Scale (dotty)
NoRaster20.51
NoVector20.10.1
YesRaster100.2N/A
YesVector (non-EMF)20.1N/A
YesEMF400.1N/A

4.9.1 Scaling by X-dimension and Resolution

An alternative way to specify the scale, which takes the above details into account, is to specify measurable units using the --scalexdimdp option, which has the format

--scalexdimdp[=X[,R]]

where X is the X-dimension (in mm by default) and R is the resolution (in dpmm, dots per mm, by default). R is optional, and defaults to 12 dpmm, and X is optional or may be zero, in which case it uses a symbology-specific default. The units may be given in inches for X by appending "in", and in dpi (dots per inch) for R by appending "dpi". For example

zint -d "1234" --scalexdimdp=0.013in,300dpi

Explicit metric units may also be given (for clarity) by appending "mm" and "dpmm" as appropriate, and may be mixed with U.S. units:

zint -d "1234" --scalexdimdp=0.33mm,300dpi

4.9.2 Scaling Example

The GS1 General Specifications 26.0 Section 5.2.6.6 “Symbol dimensions at nominal size” gives an example of an EAN-13 barcode using the X-dimension of 0.33mm. To print that example as a PNG at 12 dpmm, the approximate equivalent of 300 dpi (dpi = dpmm * 25.4), specify a scale of 2, since 0.33 * 12 = 3.96 pixels, or 4 pixels rounding to the nearest pixel:

zint -b EAN13 -d "501234567890" --compliantheight --scale=2

This will result in output of 37.29mm x 25.56mm (WxH) at 12 dpmm. The same result can be achieved using the --scalexdimdp option with

zint -b EAN13 -d "501234567890" --compliantheight --scalexdimdp

as 0.33mm is the default X-dimension for EAN, and 12 dpmm the default resolution.

4.9.3 MaxiCode Raster Scaling

For MaxiCode symbols, which use hexagons, the scale for raster output is multiplied by 10 before being applied. The 0.5 increment recommended for normal raster output does not apply.

The minimum scale is 0.2, so the minimum X-dimension is 2 pixels. However scales below 0.5 are not recommended and may produce symbols that are not within the following size ranges.

MaxiCode symbols have fixed size ranges of 24.82mm to 27.93mm in width, and 23.71mm to 26.69mm in height, excluding quiet zones. The default X-dimension is 0.88mm. For example, to output at the default X-dimension at 600 dpi specify:

zint -b MAXICODE -d "MaxiCode (19 chars)" --scalexdimdp=0,600dpi

4.10 Human Readable Text (HRT) Options

For linear barcodes the text present6 in the output image can be removed by using the --notext option. Note also that for raster output text will not be printed for scales less than 1 (see 4.9 Adjusting Image Size (X-dimension)).

Text can be set to bold using the --bold option, or a smaller font can be substituted using the --small option. The --bold and --small options can be used together if required, but only for vector output.

zint --bold -d "This Text" --small
Figure 20: zint --bold -d "This Text" --small

The gap between the barcode and the text can be adjusted using the --textgap option, where the gap is given in X-dimensions, and may be negative (minimum -5.0X, maximum 10.0X). The default gap is 1X. Note that a very small gap may cause accented texts to overlap with the barcode:

zint -d "Áccent" --textgap=0.1
Figure 21: zint -d "Áccent" --textgap=0.1

For SVG output, the font preferred by Zint (monospaced “OCR-B” for EAN/UPC, “Arimo” - a proportional sans-serif font metrically compatible with “Arial” - for all others) can be embedded in the file for portability using the --embedfont option:

zint -d "Áccent" --embedfont
Figure 22: zint -d "Áccent" --embedfont

4.11 Input Modes

4.11.1 Unicode, Data, and GS1 Modes

By default all CLI input data is assumed to be encoded in UTF-8 format. Many barcode symbologies encode data using the Latin-1 (ISO/IEC 8859-1 plus ASCII) character set, so input is converted from UTF-8 to Latin-1 before being put in the symbol. In addition QR Code and its variants and Han Xin Code can by default encode Japanese (Kanji) or Chinese (Hanzi) characters which are also converted from UTF-8.

There are two exceptions to the Latin-1 default: Grid Matrix, whose default character set is GB 2312 (Chinese); and UPNQR, whose default character set is Latin-2 (ISO/IEC 8859-2 plus ASCII).

Table 7: Default Character Sets
SymbologyDefault character setsAlternate if input not Latin-1
Aztec CodeLatin-1None
Codablock FLatin-1None
Code 128Latin-1None
Code 16KLatin-1None
Code OneLatin-1None
Data MatrixLatin-1None
DotCodeLatin-1None
Grid MatrixGB 2312 (includes ASCII)N/A
Han XinLatin-1GB 18030 (includes ASCII)
MaxiCodeLatin-1None
MicroPDF417Latin-1None
Micro QR CodeLatin-1Shift JIS (includes ASCII7)
PDF417Latin-1None
QR CodeLatin-1Shift JIS (see above)
rMQRLatin-1Shift JIS (see above)
UltracodeLatin-1None
UPNQRLatin-2N/A
All othersASCIIN/A

If Zint encounters characters which can not be encoded using the default character encoding then it will take advantage of the ECI (Extended Channel Interpretations) mechanism to encode the data if the symbology supports it - see 4.11.2 Input Modes and ECI below.

GS1 data can be encoded in a number of symbologies - see 4.11.3 GS1 Data Entry and Options.

Health Industry Barcode (HIBC) data may be encoded in the symbologies Aztec Code, Codablock F, Code 128, Code 39, Data Matrix, MicroPDF417, PDF417 and QR Code. Within this mode, the leading '+' and the check character are automatically added by Zint, conforming to HIBC Labeler Identification Code (HIBC LIC). For HIBC Provider Applications Standard (HIBC PAS), preface the data with a slash '/'.

The --binary option encodes the input data as given. Automatic code page translation to an ECI page is disabled, and no validation of the data’s encoding takes place. This may be used for raw binary or binary encrypted data. This switch plays together with the built-in ECI logic and examples may be found below.

The --fullmultibyte option uses the multibyte modes of QR Code, Micro QR Code, Rectangular Micro QR Code, Han Xin Code and Grid Matrix for non-ASCII data, maximizing density. This is achieved by using compression designed for Kanji/Hanzi characters; however some decoders take blocks which are encoded this way and interpret them as Kanji/Hanzi characters, thus causing data corruption. Symbols encoded with this option should be checked against decoders before they are used. The popular open-source ZXing decoder is known to exhibit this behaviour.

4.11.2 Input Modes and ECI

If your data contains characters that are not in the default character set, you may encode it using an ECI-aware symbology and an ECI value from Table 9: ECI Codes below. The ECI information is added to your code symbol as prefix data. The symbologies that support ECI are:

Table 8: ECI-Aware Symbologies
Aztec CodeData MatrixGrid MatrixMaxiCodePDF417rMQR
Code OneDotCodeHan Xin CodeMicroPDF417QR CodeUltracode

Be aware that not all barcode readers support ECI mode, so this can sometimes lead to unreadable barcodes. If you are using characters beyond those supported by the default character set then you should check that the resulting barcode can be understood by your target barcode reader.

The ECI value may be specified with the --eci switch, followed by the value in the column "ECI Code" in the table below. The input data should be UTF-8 formatted. Zint automatically translates the data into the target encoding.

Table 9: ECI Codes
ECI CodeCharacter Encoding Scheme (ISO/IEC 8859 schemes include ASCII)
3ISO/IEC 8859-1 - Latin alphabet No. 1
4ISO/IEC 8859-2 - Latin alphabet No. 2
5ISO/IEC 8859-3 - Latin alphabet No. 3
6ISO/IEC 8859-4 - Latin alphabet No. 4
7ISO/IEC 8859-5 - Latin/Cyrillic alphabet
8ISO/IEC 8859-6 - Latin/Arabic alphabet
9ISO/IEC 8859-7 - Latin/Greek alphabet
10ISO/IEC 8859-8 - Latin/Hebrew alphabet
11ISO/IEC 8859-9 - Latin alphabet No. 5 (Turkish)
12ISO/IEC 8859-10 - Latin alphabet No. 6 (Nordic)
13ISO/IEC 8859-11 - Latin/Thai alphabet
15ISO/IEC 8859-13 - Latin alphabet No. 7 (Baltic)
16ISO/IEC 8859-14 - Latin alphabet No. 8 (Celtic)
17ISO/IEC 8859-15 - Latin alphabet No. 9
18ISO/IEC 8859-16 - Latin alphabet No. 10
20Shift JIS (JIS X 0208 and JIS X 0201)
21Windows 1250 - Latin 2 (Central Europe)
22Windows 1251 - Cyrillic
23Windows 1252 - Latin 1
24Windows 1256 - Arabic
25UTF-16BE (High order byte first)
26UTF-8
27ASCII (ISO/IEC 646 IRV)
28Big5 (Taiwan) Chinese Character Set
29GB 2312 (PRC) Chinese Character Set
30Korean Character Set EUC-KR (KS X 1001:2002)
31GBK Chinese Character Set
32GB 18030 Chinese Character Set
33UTF-16LE (Low order byte first)
34UTF-32BE (High order bytes first)
35UTF-32LE (Low order bytes first)
170ISO/IEC 646 Invariant8
8998-bit binary data9

An ECI value of 0 does not encode any ECI information in the code symbol (unless the data contains non-default character set characters). In this case, the default character set applies (see Table 7: Default Character Sets above).

If no ECI is specified or a value of 0 is given, and the data does contain characters other than in the default character set, then Zint will automatically insert the appropriate single-byte ECI if possible (ECIs 3 to 24, excluding ECI 20), or failing that ECI 26 (UTF-8). A warning will be generated. This mechanism is not applied if the --binary option is given.

Multiple ECIs can be specified using the --segN options - see 4.16 Multiple Segments.

Note: the --eci=3 specification should only be used for special purposes. Using this parameter, the ECI information is explicitly added to the symbol. Nevertheless, for ECI Code 3, this is not usually required, as this is the default encoding for most barcodes, which is also active without any ECI information.

4.11.2.1 Input Modes and ECI Example 1

The Euro sign U+20AC can be encoded in ISO/IEC 8859-15. The Euro sign has the ISO/IEC 8859-15 codepoint hex "A4". It is encoded in UTF-8 as the hex sequence: "E2 82 AC". Those 3 bytes are contained in the file "utf8euro.txt". This command will generate the corresponding code:

zint -b DATAMATRIX --scale=10 --eci=17 -i utf8euro.txt

This is equivalent to the commands (using the --esc switch):

zint -b DATAMATRIX --scale=10 --eci=17 --esc -d "\xE2\x82\xAC"

zint -b DATAMATRIX --scale=10 --eci=17 --esc -d "\u20AC"

and to the command:

zint -b DATAMATRIX --scale=10 --eci=17 -d "€"
zint -b DATAMATRIX --eci=17 -d "€"
Figure 23: zint -b DATAMATRIX --eci=17 -d "€"

4.11.2.2 Input Modes and ECI Example 2

The Chinese character with the Unicode codepoint U+5E38 can be encoded in Big5 encoding. The Big5 representation of this character is the two hex bytes: "B1 60" (contained in the file "big5char.txt"). The generation command for Data Matrix is:

zint -b DATAMATRIX --scale=10 --eci=28 --binary -i big5char.txt

This is equivalent to the command (using the --esc switch):

zint -b DATAMATRIX --scale=10 --eci=28 --binary --esc -d "\xB1\x60"

and to the commands (no --binary switch so conversion occurs):

zint -b DATAMATRIX --scale=10 --eci=28 --esc -d "\xE5\xB8\xB8"

zint -b DATAMATRIX --scale=10 --eci=28 --esc -d "\u5E38"

zint -b DATAMATRIX --scale=10 --eci=28 -d "常"
zint -b DATAMATRIX --eci=28 -d "\u5E38" --esc
Figure 24: zint -b DATAMATRIX --eci=28 -d "\u5E38" --esc

4.11.2.3 Input Modes and ECI Example 3

Some decoders (in particular mobile app ones) for QR Code assume UTF-8 encoding by default and do not support ECI. In this case supply UTF-8 data and use the --binary switch so that the data will be encoded as UTF-8 without conversion:

zint -b QRCODE --binary -d "UTF-8 data"
zint -b QRCODE --binary -d "\xE2\x82\xAC\xE5\xB8\xB8" --esc
Figure 25: zint -b QRCODE --binary -d "\xE2\x82\xAC\xE5\xB8\xB8" --esc

4.11.3 GS1 Data Entry and Options

The following symbologies accept GS1 data:

Table 10: GS1-Enabled Symbologies
SymbologyImplicit AI?GS1 Data Assumed?Supports GS1 Composite?
Aztec CodeNoNoNo
Code 16KNoNoNo
Code 49NoNoNo
Code OneNoNoNo
Data MatrixNoNoNo
DotCodeNoNoNo
EAN-13, EAN-8Yes (01)YesYes
EAN-14Yes (01)YesNo
GS1-128NoYesYes
GS1 DataBar Expanded (including Stacked)NoYesYes
GS1 DataBar (all others)Yes (01)YesYes
NVE-18Yes (00)YesNo
QR CodeNoNoNo
rMQRNoNoNo
UltracodeNoNoNo
UPC-A, UPC-EYes (01)YesYes

4.11.3.1 GS1 Data Entry

Those that encode an implicit AI take numeric data in their linear part without any further markup - see respective descriptions in 6. Types of Symbology.

GS1-128, GS1 DataBar Expanded (including Expanded Stacked), the matrix symbologies and the 2D component of GS1 Composite symbologies, all of which can encode multiple AIs, require markup in the data to distinguish AIs.

The traditional way in Zint of specifying GS1 data for these cases is to delimit the GS1 AIs in square brackets:

zint -b AZTEC -d "[01]09520123456788[10]BCH4[21]07" --gs1

(Note that for the matrix symbologies the --gs1 option must be given.)

Parentheses (round brackets) may be used instead by giving the --gs1parens option:

zint -b AZTEC -d "(01)09520123456788(10)BCH4(21)07" --gs1parens

If the data includes opening parentheses when using the latter format, they must be escaped and the --esc option given:

zint -b AZTEC -d "(01)09520123456788(90)Var\(34)" --esc --gs1parens

Closing parentheses may also be escaped for clarity.

For matrix symbologies, a GS1 Digital Link URI may be used:

zint -b AZTEC -d "https://example.com/01/09520123456788/10/BCH4/21/07" --gs1

A further way to specify GS1 input is “Unbracketed AI”, a GS1 Syntax Engine format10 that uses carets (^) to indicate any required FNC1s.11 The data must start with a caret:

zint -b AZTEC -d "^010952012345678810BCH4^2107" --gs1

The final way to specify input is the related “raw” mode using the --gs1raw option. Here FNC1s are indicated by Group Separators (GS, ASCII 29, escape sequence \G). It does not start with a GS:

zint -b AZTEC -d "010952012345678810BCH4\G2107" --esc --gs1raw

4.11.3.2 GS1 Options

Apart from --gs1, --gs1parens and --gs1raw discussed above, there are two other GS1 options.

  • --gs1strict, which enables the use the GS1 Syntax Engine to strictly validate GS1 data, including GS1 Digital Link URIs (by default Zint does not validate Digital Links at all). It requires that the gs1encoders library was present when Zint was built, otherwise the default built-in validation will be used.

  • --gs1nocheck, for use with legacy systems that have data that does not conform to the current GS1 standard. Printable ASCII input is still checked for, as is the validity of GS1 data specified without AIs (e.g. linear data for GS1 DataBar Omnidirectional/Limited/etc.). Also checked is GS1 DataBar Expanded and GS1 Composite input that is not in the GS1 encodable character set 82 (see GS1 General Specifications 26.0 Table 7-2 “GS1 AI encodable character set 82”), otherwise encodation would fail. In “Unbracketed AI” and raw mode, overlong AI data will also fail.

All the GS1 options imply --gs1 (unlike their API equivalents, for which see 5.11 Setting the Input Mode).

4.12 Batch Processing

Data can be batch processed by reading from a text file and producing a separate barcode image for each line of text in that file. To do this use the --batch switch together with -i to select the input file from which to read data. For example

zint -b EAN13 --batch -i ean13nos.txt

where "ean13nos.txt" contains a list of EAN-13 numbers (GTINs), each on its own line. Zint will automatically detect the end of a line of text (in either Unix or Windows formatted text files) and produce a symbol each time it finds this.

Input files should end with a line feed character - if this is not present then Zint will not encode the last line of text, and will warn you that there is a problem.

By default Zint will output numbered filenames starting with 00001.png, 00002.png etc. To change this behaviour specify the -o option using special characters in the output filename as shown in the table below:

Table 11: Batch Filename Formatting
Input CharacterInterpretation
~Insert a number or 0
#Insert a number or space
@Insert a number or * (or + on Windows)
Any otherInsert literally

For instance

zint -b EAN13 --batch -i ean13nos.txt -o "file~~~.svg"

The following table shows some examples to clarify this method:

Table 12: Batch Filename Examples
InputFilenames Generated
-o "file~~~.svg""file001.svg", "file002.svg", "file003.svg"
-o "@@@@bar.png""***1.png", "***2.png", "***3.png" (except Windows)
-o "@@@@bar.png""+++1.png", "+++2.png", "+++3.png" (on Windows)
-o "my~~bar~.eps""my00bar1.eps", "my00bar2.eps", "my00bar3.eps"
-o "t###est.png""t 1est.png", "t 2est.png", "t 3est.png"

The special characters can span directories also, which is useful when creating a large number of barcodes:

Table 13: Batch Directory Examples
InputFilenames Generated
-o "dir~/file~~~.svg""dir0/file001.svg", "dir0/file002.svg", …
"dir0/file999.svg", "dir1/file000.svg", …

For an alternative method of naming output files see the --mirror option in 4.14 Automatic Filenames below.

4.13 Direct Output to stdout

The finished image files can be output directly to stdout for use as part of a pipe by using the --direct option. By default --direct will output data as a PNG image (or GIF image if libpng is not present), but this can be altered by supplementing the --direct option with a --filetype option followed by the suffix of the file type required. For example:

zint -b MICROPDF417 --direct --filetype=pcx -d "Data to encode"

This command will output the symbol as a PCX file to stdout. For the supported output file formats see Table 4: Output File Formats.


CAUTION: Outputting binary files to the command shell without catching that data in a pipe can have unpredictable results. Use with care!


4.14 Automatic Filenames

The --mirror option instructs Zint to use the data to be encoded as an indicator of the filename to be used. This is particularly useful if you are processing batch data. For example the input data "1234567" will result in a file named "1234567.png".

There are restrictions, however, on what characters can be stored in a filename, so the filename may vary from the data if the data includes non-printable characters, for example, and may be shortened if the data input is long.

To set the output file format use the --filetype option as detailed above in 4.13 Direct Output to stdout. To output to a specific directory use the -o option giving the name of the directory (any filename will be ignored, unless --filetype is not specified, in which case the filename’s extension will be used).

4.15 Working with Dots

Matrix codes can be rendered as a series of dots or circles rather than the normal squares by using the --dotty option. This option is only available for matrix symbologies, and is automatically selected for DotCode. The size of the dots can be adjusted using the --dotsize option followed by the diameter of the dot, where that diameter is in X-dimensions. The minimum dot size is 0.01, the maximum is 20. The default size is 0.8.

The default and minimum scale for raster output in dotty mode is 1.

zint -b CODEONE -d "123456789012345678" --dotty --vers=9
Figure 26: zint -b CODEONE -d "123456789012345678" --dotty --vers=9

4.16 Multiple Segments

If you need to specify different ECIs for different sections of the input data, the --seg1 to --seg9 options can be used. Each option is of the form --segN=ECI,data where ECI is the ECI code (see Table 9: ECI Codes) and data is the data to which this applies. This is in addition to the ECI and data specified using the --eci and -d options which must still be present and which in effect constitute segment 0. For instance

zint -b AZTEC_CODE --eci=9 -d "Κείμενο" --seg1=7,"Текст" --seg2=20,"文章"

specifies 3 segments: segment 0 with ECI 9 (Greek), segment 1 with ECI 7 (Cyrillic), and segment 2 with ECI 20 (Shift JIS). Segments must be consecutive.

Naturally the symbology must be ECI-aware (see Table 8: ECI-Aware Symbologies).

zint -b AZTEC --eci=9 -d "Κείμενο" --seg1=7,"Текст" --seg2=20,"文章"
Figure 27: zint -b AZTEC --eci=9 -d "Κείμενο" --seg1=7,"Текст" --seg2=20,"文章"

ECIs of zero may be given, in which case Zint will automatically determine an ECI if necessary, as described in section 4.11.2 Input Modes and ECI.

Multiple segments are not currently supported for use with GS1 data.

4.17 Structured Append

Structured Append is a method of splitting data among several symbols so that they form a sequence that can be scanned and re-assembled in the correct order on reading, and is available for Aztec Code, Code One, Data Matrix, DotCode, Grid Matrix, MaxiCode, MicroPDF417, PDF417, QR Code and Ultracode.

The --structapp option marks a symbol as part of a Structured Append sequence, and has the format

--structapp=I,C[,ID]
zint -b DATAMATRIX -d "2nd of 3" --structapp="2,3,5006"
Figure 28: zint -b DATAMATRIX -d "2nd of 3" --structapp="2,3,5006"

where I is the index (position) of the symbol in the Structured Append sequence, C is the count or total number of symbols in the sequence, and ID is an optional identifier (not available for Code One, DotCode or MaxiCode) that is the same for all symbols belonging to the same sequence. The index is 1-based and goes from 1 to count. Count must be 2 or more. See the individual symbologies for further details.

4.18 Help Options

There are three help options which give information about how to use the command line. The -h or --help option will display a list of all of the valid options available, and also gives the exact version of the software (the version by itself can be displayed with -v or --version).

The -t or --types option gives the table of symbologies listing the symbol ID numbers and names.

The -e or --ecinos option gives a list of the ECI codes.

4.19 Other Options

Zint can output a representation of the symbol data as a set of hexadecimal values if asked to output to a text file ("*.txt") or if given the option --filetype=txt or the option --dump. This can be used for test and diagnostic purposes.

Also there’s the --verbose option which will output debug information to stdout.

Additional options are available which are specific to certain symbologies. These may, for example, control the amount of error correction data or the size of the symbol. These options are discussed in section 6. Types of Symbology of this guide.