barcode()
Usage
barcode(type, data[, width = 200, height = 200 [, hintKey, hintValue]])
Structr.barcode(type, data[, width = 200, height = 200 [, hintMap]])
Description
Creates a barcode image of the given type with the given data using the zxing library. The library supports several different barcode types.
Barcode Type | Result |
---|---|
AZTEC | Aztec 2D barcode format (beta) |
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 | PDF417 format (beta) |
QR_CODE | QR Code 2D barcode format |
RSS_14 | RSS 14 |
RSS_EXPANDED | RSS EXPANDED |
UPC_A | UPC-A 1D format |
UPC_E | UPC-E 1D format |
UPC_EAN_EXTENSION | UPC/EAN extension format. Not a stand-alone format |
Most barcode types support different hints which are explained under here. Probably the most interesting hints are MARGIN
and ERROR_CORRECTION
. Following is an excerpt from the source code. More information on the error correction level can be found here
/**
* Specifies margin, in pixels, to use when generating the barcode. The meaning can vary
* by format; for example it controls margin before and after the barcode horizontally for
* most 1D formats. (Type {@link Integer}, or {@link String} representation of the integer value).
*/
MARGIN
/**
* Specifies what degree of error correction to use, for example in QR Codes.
* Type depends on the encoder. For example for QR codes it's type
* {@link com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ErrorCorrectionLevel}.
* For Aztec it is of type {@link Integer}, representing the minimal percentage of error correction words.
* For PDF417 it is of type {@link Integer}, valid values being 0 to 8.
* In all cases, it can also be a {@link String} representation of the desired value as well.
* Note: an Aztec symbol should have a minimum of 25% EC words.
*/
ERROR_CORRECTION
Examplary usage in a dynamic file
- File content:
${barcode('QR_CODE', 'My testcode', 200, 200, "MARGIN", 0, "ERROR_CORRECTION", "Q")}
- File content-type:
image/png;charset=ISO-8859-1
Examplary usage in a HTML IMG tag
src
attribute:data:image/png;base64, ${base64encode(barcode('QR_CODE', 'My testcode', 200, 200, 'MARGIN', 0, 'ERROR_CORRECTION', 'Q'), 'basic', 'ISO-8859-1')}