Constructor
new BarcodeGenerator(encodeType, codeText)
Parameters:
| Name | Type | Description |
|---|---|---|
encodeType |
Barcode symbology type. Use EncodeTypes class to setup a symbology | |
codeText |
Text to be encoded. |
- Source:
Throws:
Methods
(static) importFromXml(filePath)
Imports BarCode properties from the xml-file specified and creates BarcodeGenerator instance.
Parameters:
| Name | Type | Description |
|---|---|---|
filePath |
The name of the file |
Returns:
| Type | Description |
|---|---|
| BarcodeGenerator instance |
- Source:
exportToXml(filePath)
Parameters:
| Name | Type | Description |
|---|---|---|
filePath |
The xml file |
Returns:
| Type | Description |
|---|---|
| Whether or not export completed successfully. Returns True in case of success; False Otherwise |
- Source:
Throws:
generateBarCodeImage(format) → {String}
Parameters:
| Name | Type | Description |
|---|---|---|
format |
BarCodeImageFormat | BarCodeImageFormat value (PNG, BMP, JPEG, GIF) |
Returns:
| Type | Description |
|---|---|
| String | base64 representation of image. |
- Source:
Example
let generator = new BarCodeGenerator(EncodeTypes.CODE_128);
let image = generator.generateBarCodeImage(BarCodeImageFormat.GIF);
getBarcodeType()
- Source:
getCodeText()
- Source:
getParameters()
Returns:
| Type | Description |
|---|---|
| BaseGenerationParameters |
- Source:
save(filePath, format)
Parameters:
| Name | Type | Description |
|---|---|---|
filePath |
String | Path to save to. |
format |
BarCodeImageFormat | BarCodeImageFormat value (PNG, BMP, JPEG, GIF) |
- Source:
Example
let generator = new BarCodeGenerator(EncodeTypes.CODE_128);
generator.save("file path", BarCodeImageFormat.GIF);
setBarcodeType()
- Source:
setCodeText(codeText, encoding, insertBOM)
Encodes the Unicode {@code codeText} into a byte sequence using the specified {@code encoding}. UTF-8 is the most commonly used encoding. If the encoding supports it and {@code insertBOM} is set to {@code true}, the function includes a {@code byte order mark (BOM)}.
This function is intended for use with 2D barcodes only (e.g., Aztec, QR, DataMatrix, PDF417, MaxiCode, DotCode, HanXin, RectMicroQR, etc.). It enables manual encoding of Unicode text using national or special encodings; however, this method is considered obsolete in modern applications. For modern use cases, {@code ECI} encoding is recommended for Unicode data.
Using this function with 1D barcodes, GS1-compliant barcodes (including 2D), or HIBC barcodes (including 2D) is not supported by the corresponding barcode standards and may lead to unpredictable results.
This example shows how to use {@code SetCodeText} with or without a BOM for 2D barcodes.
//Encode codetext using UTF-8 with BOM let gen = new BarcodeGenerator(EncodeTypes.QR, null); gen.setCodeText("車種名", "UTF-8", true); gen.save("barcode.png", BarCodeImageFormat.PNG); let reader = new BarCodeReader("barcode.png", null, DecodeType.QR); let results = reader.readBarCodes(); for(let i = 0; i < results.length; i++) { let result = results[i]; console.log("BarCode CodeText: " + result.getCodeText()); } //Encode codetext using UTF-8 without BOM let gen = new BarcodeGenerator(EncodeTypes.QR, null); gen.setCodeText("車種名", "UTF-8", false); gen.save("barcode.png", BarCodeImageFormat.PNG); let reader = new BarCodeReader("barcode.png", null, DecodeType.QR); let results = reader.readBarCodes(); for(let i = 0; i < results.length; i++) { let result = results[i]; console.log("BarCode CodeText: " + result.getCodeText()); }
Parameters:
| Name | Type | Description |
|---|---|---|
codeText |
CodeText string | |
encoding |
Applied encoding | |
insertBOM |
Indicates whether to insert a byte order mark (BOM) when the specified encoding supports it (e.g., UTF-8, UTF-16, UTF-32). If set to {@code true}, the BOM is added; if {@code false}, the BOM is omitted even if the encoding normally uses one. |
- Source: