Barcodes Syntax and Properties

Inserting Barcodes Dynamically

You can insert barcode images to your documents dynamically using barcode tags. To declare a dynamically inserted barcode image within your template, perform the following steps:

  1. Add a textbox to your template at the place where you want a barcode image to be inserted.
  2. Set common image attributes such as size, rotation angle, and others for the textbox, making the textbox look like a barcode image without bars and text.
  3. Specify a barcode tag within the textbox using the following syntax:
<<barcode [barcode_expression] -barcode_type>>

During run-time, an expression declared within a barcode tag is evaluated, its value is encoded using the specified barcode type, and the tag’s containing textbox is filled with a corresponding barcode image. The tag itself is removed from the textbox then.
To specify a barcode type within a barcode tag, you can use one of the predefined identifiers described in the following table:

codabarCODABAR Barcode
code11CODE 11 barcode
code39SStandard CODE 39 barcode
code39EExtended CODE 39 barcode
code93SStandard CODE 93 barcode
code93EExtended CODE 93 barcode
code128CODE 128 barcode
code128GS1GS1 CODE 128 barcode specification. The barcode text must contain parentheses for A
ean8EAN-8 barcode
ean13EAN-13 barcode
ean14EAN-14 barcode
scc14SCC-14 barcode
sscc18SSCC-18 barcode
upcaUPC-A barcode
upceUPC-E barcode
isbnISBN barcode
issnISSN barcode
ismnISMN barcode
stfStandard 2 of 5 barcode
itfInterleaved 2 of 5 barcode
mtfMatrix 2 of 5 barcode
ip25Italian Post 25 barcode
iatatfIATA 2 of 5 barcode. IATA (International Air Transport Assosiation) uses this barcode for the management of air cargo
itf14ITF14 barcode
itf6ITF-6 barcode
msiMSI Plessey barcode
vinVIN (Vehicle Identification Number) barcode
dpiDeutschen Post barcode, also known as Identcode, CodeIdentcode, German Postal 2 of 5 Identcode, Deutsche Post AG Identcode, Deutsche Frachtpost Identcode, Deutsche Post AG (DHL)
dplDeutsche Post Leitcode barcode, also known as German Postal 2 of 5 Leitcode, CodeLeitcode, Leitcode, Deutsche Post AG (DHL)
opcOPC (Optical Product Code) barcode, also known as VCA barcode, VCA OPC, Vision Council of America OPC barcode
pznPZN barcode, also known as Pharma Zentral Nummer, Pharmazentralnummer
code16KCode 16K barcode
pharmacodeRepresents Pharmacode barcode, also known as Code32
dmDataMatrix barcode
qrQR Code barcode
aztecAztec barcode
pdf417Pdf417 barcode
macroPdf417MacroPdf417 barcode
dmGS1DataMatrix barcode with GS1 string format
microPdf417MicroPdf417 barcode
qrGS1QR barcode with GS1 string format
maxiCodeMaxiCode barcode
dotCodeDotCode barcode
apAustralia Post Customer barcode
postnetPostnet barcode
planetPlanet barcode
oneCodeUSPS OneCode barcode
rm4sccRM4SCC barcode. RM4SCC (Royal Mail 4-state Customer Code) is used for automated mail sort process in UK
databarODDatabar omni-directional barcode
databarTDatabar truncated barcode
databarLDatabar limited barcode
databarEDatabar expanded barcode
databarESDatabar expanded stacked barcode
databarSDatabar stacked barcode
databarSODDatabar stacked omni-directional barcode
spSingapore Post barcode
apeAustralian Post Domestic eParcel barcode
sppSwiss Post Parcel barcode. Supported types: Domestic Mail, International Mail, Additional Services
patchCodePatch code barcode
code32Code32 barcode
dltfDataLogic 2 of 5 barcode
dkixDutch KIX barcode
codablockFCodablock F barcode
codablockFGS1GS1 Codablock F barcode
code128GS1UPCAGS1-128 AI 8102 Coupon Extended barcode
databarGS1UPCAUPCA & GS1 Databar Coupon barcode

Scaling Barcode Symbols

You can scale barcode symbols of dynamically inserted barcode images specifying the scale attribute for a barcode tag as follows.

<<barcode [barcode_expression] -barcode_type scale="scaling_hint">>

A scale attribute affects the width and height of a 2D barcode symbol and the width of a 1D barcode symbol. The value of a scale attribute represents the percent of barcode symbol scaling.
The value of a scale attribute, however, is just a hint. That is, actual scaling of a barcode symbol can be not precisely equal to the specified one. The reason is that scaling can damage a barcode symbol in a way it to become unreadable by barcode scanners. That is why, the engine calculates actual scaling not to bring such a damage trying to be as close to the specified scaling as possible at the same time.

Configuring Initial Scaling of Barcode Symbols

You can affect initial scaling of all barcode symbols generated by a single DocumentAssembler instance through the DocumentAssembler.BarcodeSettings.BaseXDimension and DocumentAssembler.BarcodeSettings.BaseYDimension properties. These properties define the smallest width and height of the unit of barcode modules respectively. That is, for example, to make all barcode symbols twice larger by default, you can use the following code:

DocumentAssembler assembler = new DocumentAssembler();
assembler.BarcodeSettings.BaseXDimension *= 2f;
assembler.BarcodeSettings.BaseYDimension *= 2f;

Values of the DocumentAssembler.BarcodeSettings.BaseXDimension and DocumentAssembler.BarcodeSettings.BaseYDimension properties are measured in units defined by the DocumentAssembler.BarcodeSettings.GraphicsUnit property.

Setting Height of 1D Barcode Symbols

The height of a 1D barcode symbol is not affected by the scale attribute of the corresponding barcode tag. However, you can set the height applying the barHeight attribute as follows:

<<barcode [barcode_expression] -barcode_type barHeight="height">>

The value of a barHeight attribute specifies the percent of the overall barcode image height. That is, for example, to set the height of a barcode symbol equal to two thirds of its overall barcode image height, you can use the following barcode tag:

<<barcode ["736192"] -codabar barHeight="67">>

Customizing Fore and Back Colors of Barcode Images

The fore color of a dynamically inserted barcode image is used to render the barcode’s symbol and text. This color is derived from the font of the corresponding barcode tag. The background color of the image is derived from the solid fill of the textbox containing the tag.

Customizing Font and Placement of Barcode Text

The font used to render barcode text of a dynamically inserted barcode image derives the following attributes from the font of the corresponding barcode tag:

  • Name
  • Size
  • Style (bold and italic)
  • Color

The placement of barcode text of a dynamically inserted barcode image – leftward, rightward, or centered – is defined by text alignment of the corresponding barcode tag.

Using Barcode Text Auto-Correction

For a dynamically inserted barcode image, the engine automatically corrects barcode text that does not conform the barcode’s specification, if possible.

To disable the auto-correction making the engine throw an exception in case of an invalid barcode text, you can set the DocumentAssembler.BarcodeSettings.UseAutoCorrection property to false.

Setting Barcode Image Resolution

You can set horizontal and vertical resolution for dynamically inserted barcode images in DPI (dots per inch) using the DocumentAssembler.BarcodeSettings.Resolution property. That is, for example, to set both horizontal and vertical resolution to 300 DPI, you can use the following code:

DocumentAssembler assembler = new DocumentAssembler();
assembler.BarcodeSettings.Resolution = 300;

Example with Output

<<barcode ["736192"] -codabar>>

Generated bar code for the above mentioned syntax is: