The Zxing ("Zebra Crossing") module is used to create barcodes or QR codes and display them in image form in a document. This module uses the open-source Java ZXing framework: https://github.com/zxing/zxing.
It is based on ZXing version 3.5.1.
This module supports the creation of the following types of 1D or 2D (one- or two-dimensional) barcodes:
1D product
|
1D industrial
|
2D |
UPC-A
|
Code 39
|
QR Code
|
UPC-E
|
Code 93
|
Data Matrix
|
EAN-8
|
Code 128 |
Aztec
|
EAN-13
|
Codabar
|
PDF 417
|
UPC/EAN Extension 2/5 |
ITF
|
MaxiCode
|
|
|
RSS-14
|
|
|
RSS-Expanded
|
The ZXing module is used in an APE template with the aid of an inclusion directive to insert at the start of the template:
<#import "/lib_xzingbarcode.ftl" as zxingModule/>
Note: The "zxingModule" namespace name is provided as an example and can be replaced by a name of your choosing (in accordance with Apache Freemarker namespaces syntax).
This module offers a macro called "barcode" to represent all the different types of supported barcodes. This macro has no content (no end tags). Barcodes are described by entering the barcode parameters:
Parameter type |
Parameter name |
Description |
String |
type |
1D/2D barcode type from the following values:
aztec : Aztec 2D barcode format,
codabar: CODABAR 1D format,
code_39: Code 39 1D format,
code_93: Code 93 1D format,
code_128: Code 128 1D format,
data_matrix : Data Matrix 2D barcode format,
ean_8: EAN-8 1D format,
ean_13: EAN-13 1D format,
ITF ITF (Interleaved Two of Five) 1D format,
maxicode: MaxiCode 2D barcode format,
pdf_417: PDF 417 2D barcode format,
qr_code: QR Code 2D barcode format,
rss_14: RSS-14 2D barcode format,
rss_expanded: RSS-Expanded 2D barcode format,
upc-a: UPC-A 1D format,
upc_e: UPC-E 1D format,
upc_ean_extension: UPC/EAN extension format. Not a stand-alone format.
|
String |
content |
Numeric or alphanumeric data to display in barcode form. |
Number
|
width
|
The required width in image pixels representing the barcode. The actual value can be slightly different from the required width according to the chosen format constraints. |
Number
|
height
|
The required height in image pixels representing the barcode. The actual value can be slightly different from the required height according to the chosen format constraints. |
Parameter type |
Parameter name |
Description |
Hash |
hints |
Display options depending on the chosen type. Each option is defined by a name/value pair and all the options are grouped in a Hash object. See more detailed Java ZXing framework documentation on the subject: https://zxing.github.io/zxing/apidocs/com/google/zxing/EncodeHintType.html. The option name must be defined with one of the names in the following list:
- aztec_layers: Specifies the required number of layers for an "aztec" barcode. The value must be a number between -4 and 32.
- character_set: Specifies the character encoding to use. The value must be a character string.
- code128_compact: Specifies the use of compact mode for a "code_128" barcode. The value must be a boolean.
- data_matrix_compact: Specifies the use of compact mode for a "data_matrix" barcode. The value must be a boolean.
- data_matrix_shape: Specifies the matrix shape for a "data_matrix" barcode. The value must be a character string. . Possible values: "FORCE_NONE", "FORCE_RECTANGLE" and "FORCE_SQUARE".
- error_correction: Specifies the degree of error correction to use. For the "qr_code" type, the value must be a character string. Possible values: "H", "L", "M" and "Q". For the "aztec" type, the value must be digital. For the "pdf_417" type, the value must be a number between 0 and 8,
- force_c40: Specifies the use of C40 encoding for a "data_matrix" barcode. The value must be a boolean,
- force_code_set: Specifies the encoding to use for a "code_128" barcode. The value must be a character string. Possible values: "A", "B" and "C".
- gs1_format: Specifies if the data must be encoded according to the GS1 standard. The value must be a boolean,
- margin: Specifies the margin in pixels to use to generate the barcode. The value must be a number.
- pdf417_auto_eci: Specifies if ECIs need to be inserted automatically during PDF417 encoding for a "pdf_417" barcode. The value must be a boolean.
- pdf417_compact: Specifies the use of compact mode for a "pdf_417" barcode. The value must be a boolean.
- pdf417_compaction: Specifies the compaction mode to use during PDF417 encoding for a "pdf_417" barcode. The value must be a character string. Possible values: "AUTO", "BYTE", "NUMERIC" and "TEXT".
- pdf417_dimensions: Specifies the minimum and maximum number of rows and columns to use during PDF417 encoding for a "pdf_417" barcode. The value must be a Hash object with the following properties:
- min_cols: Minimum number of columns. The value must be a number.
- max_cols: Maximum number of columns. The value must be a number.
- min_rows: Minimum number of rows. The value must be a number.
- max_rows: Maximum number of rows. The value must be a number.
- qr_compact: Specifies the use of compact mode for a "qr_code" barcode. The value must be a boolean,
- qr_mask_pattern: Specifies the QR code mask pattern to use for a "qr_code" barcode. The value must be a number between 0 and 7.
- qr_version: Specifies the version of QR code to use for a "qr_code" barcode. The value must be a number.
|
Any
|
inner* |
The barcode macro uses the foExternalGraphic macro to display the barcode image (in PNG format) in the APE template. Parameters specific to the generated foExternalGraphic macro can be specified by prefixing the parameter name with the "inner" string and putting the first letter of the parameter in upper case.
|
String |
oncolor |
Barcode foreground color. A color can be specified in several ways:
- by using #RRGGBB hexadecimal notation, used to describe an opaque color where RR, GG and BB represent the red, green and blue component respectively in hexadecimal values between 00 and FF. To describe a transparent color, #RRGGBBAA notation is used where RR, GG and BB are between 00 and FF, and where AA represents the transparency in hexadecimal, ranging from 00 (completely transparent color) to FF (totally opaque color),
- using the RGB notation (RR, GG, BB) used to describe an opaque color where RR, GG and BB represent the decimal value of the red, green and blue component respectively, with values between 0 and 255,
- using RGBA notation (RR, GG, BB, AA) used to describe a transparent color where RR, GG and BB represent the decimal value of the red, green and blue component respectively, with values between 0 and 255. The AA component represents the decimal value of transparency, ranging from 0 (completely transparent color) to 1 (completely opaque color).
The default value is black. |
String |
offcolor |
Barcode background color. A color can be specified in several ways:
- by using #RRGGBB hexadecimal notation, used to describe an opaque color where RR, GG and BB represent the red, green and blue component respectively in hexadecimal values between 00 and FF. To describe a transparent color, #RRGGBBAA notation is used where RR, GG and BB are between 00 and FF, and where AA represents the transparency in hexadecimal, ranging from 00 (completely transparent color) to FF (totally opaque color),
- using the RGB notation (RR, GG, BB) used to describe an opaque color where RR, GG and BB represent the decimal value of the red, green and blue component respectively, with values between 0 and 255,
- using RGBA notation (RR, GG, BB, AA) used to describe a transparent color where RR, GG and BB represent the decimal value of the red, green and blue component respectively, with values between 0 and 255. The AA component represents the decimal value of transparency, ranging from 0 (completely transparent color) to 1 (completely opaque color).
The default value is white. |
For example:
<#-- Display a QRCode -->
<#assign hintsQRCode = {"error_correction": "H", "qr_mask_pattern": 2} />
<@zxingModule.barcode type="qr_code" content="https://www.hardis-group.com/" width=150 height=150 hints=hintsQRCode innerBorder="2px solid black" />
<#-- Display a Code 128 -->
<@zxingModule.barcode type="code_128" content="SW-02643/1" width=100 height=50 hints={"force_code_set" : "A"} />
<#-- Display a itf with fushsia semi transparent drawing color -->
<@zxingModule.barcode type="itf" content="02345673" width=150 height=100 oncolor="rgba(255,0,255, 0.48)"/>
<@zxingModule.barcode type="itf" content="02345673" width=150 height=100 oncolor="#FF00FF7A"/>
<#-- Display a Code 128 with totaly transparent backgroud color -->
<@zxingModule.barcode type="code_128" content="SW-02643/1" width=150 height=100 offcolor="#00000000"/>
↑ Top of page