BarcodeGenerator
Inheritance: java.lang.Object
public final class BarcodeGenerator
BarcodeGenerator for backend barcode images generation.
supported symbologies: 1D: Codabar, Code11, Code128, Code39, Code39FullASCII Code93, Code93Extended, EAN13, EAN8, Interleaved2of5, MSI, Standard2of5, UPCA, UPCE, ISBN, GS1Code128, Postnet, Planet EAN14, SCC14, SSCC18, ITF14, SingaporePost … 2D: Aztec, DataMatrix, PDf417, QR code …
This sample shows how to create and save a barcode image. BarCodeGenerator generator = new BarCodeGenerator(EncodeTypes.CODE_128); generator.setCodeText("123ABC"); generator.save("code128.png");
Constructors
Constructor | Description |
---|---|
BarcodeGenerator(BaseEncodeType type) | Creates an instance of BarcodeGenerator. |
BarcodeGenerator(BaseEncodeType type, String codeText) | Creates an instance of BarcodeGenerator. |
Methods
Method | Description |
---|---|
dispose() | Clean up any resources being used. |
equals(Object arg0) | |
exportToXml(OutputStream xml) | Exports BarCode properties to the xml-stream specified |
exportToXml(String xmlFile) | Exports BarCode properties to the xml-file specified |
generateBarCodeImage() | Generate the barcode image under current settings. |
getBarcodeType() | Barcode symbology type. |
getClass() | |
getCodeText() | Text to be encoded. |
getParameters() | Generation parameters. |
hashCode() | |
importFromXml(InputStream xml) | Imports BarCode properties from the xml-stream specified and creates BarcodeGenerator instance. |
importFromXml(String xmlFile) | Imports BarCode properties from the xml-file specified and creates BarcodeGenerator instance. |
notify() | |
notifyAll() | |
save(OutputStream stream, BarCodeImageFormat format) | Save barcode image to stream in specific format. |
save(String filename) | Save barcode image to specific file. |
save(String filename, BarCodeImageFormat format) | Save barcode image to specific file in specific format. |
setBarcodeType(BaseEncodeType value) | Barcode symbology type. |
setCodeText(byte[] codeBytes) | Set codetext as sequence of bytes. |
setCodeText(String value) | Text to be encoded. |
setCodeText(String codeText, Charset encoding) | |
setCodeText(String codeText, Charset encoding, boolean insertBOM) | |
toString() | |
wait() | |
wait(long arg0) | |
wait(long arg0, int arg1) |
BarcodeGenerator(BaseEncodeType type)
public BarcodeGenerator(BaseEncodeType type)
Creates an instance of BarcodeGenerator.
Parameters:
Parameter | Type | Description |
---|---|---|
type | BaseEncodeType | Barcode symbology type. Use EncodeTypes class to setup a symbology. |
BarcodeGenerator(BaseEncodeType type, String codeText)
public BarcodeGenerator(BaseEncodeType type, String codeText)
Creates an instance of BarcodeGenerator.
Parameters:
Parameter | Type | Description |
---|---|---|
type | BaseEncodeType | Barcode symbology type. Use EncodeTypes class to setup a symbology. |
codeText | java.lang.String | Text to be encoded. |
dispose()
public void dispose()
Clean up any resources being used.
equals(Object arg0)
public boolean equals(Object arg0)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | java.lang.Object |
Returns: boolean
exportToXml(OutputStream xml)
public boolean exportToXml(OutputStream xml)
Exports BarCode properties to the xml-stream specified
Parameters:
Parameter | Type | Description |
---|---|---|
xml | java.io.OutputStream | The xml-stream |
Returns: boolean - Whether or not export completed successfully. Returns True in case of success; False Otherwise
exportToXml(String xmlFile)
public boolean exportToXml(String xmlFile)
Exports BarCode properties to the xml-file specified
Parameters:
Parameter | Type | Description |
---|---|---|
xmlFile | java.lang.String | The name of the file |
Returns: boolean - Whether or not export completed successfully.
Returns True in case of success; False Otherwise
generateBarCodeImage()
public BufferedImage generateBarCodeImage()
Generate the barcode image under current settings.
This sample shows how to create and save a barcode image. BarCodeGenerator generator = new BarCodeGenerator(EncodeTypes.CODE_128); File outputFile = new File("test.png"); BufferedImage image = generator.generateBarCodeImage(); ImageIO.write(image, "png",outputFile);
Returns: java.awt.image.BufferedImage - Barcode image. See Bitmap .
getBarcodeType()
public BaseEncodeType getBarcodeType()
Barcode symbology type.
Returns: BaseEncodeType
getClass()
public final native Class<?> getClass()
Returns: java.lang.Class
getCodeText()
public String getCodeText()
Text to be encoded.
Returns: java.lang.String
getParameters()
public BaseGenerationParameters getParameters()
Generation parameters.
Returns: BaseGenerationParameters
hashCode()
public native int hashCode()
Returns: int
importFromXml(InputStream xml)
public static BarcodeGenerator importFromXml(InputStream xml)
Imports BarCode properties from the xml-stream specified and creates BarcodeGenerator instance.
Parameters:
Parameter | Type | Description |
---|---|---|
xml | java.io.InputStream | The xml-stream |
Returns: BarcodeGenerator - BarcodeGenerator instance
importFromXml(String xmlFile)
public static BarcodeGenerator importFromXml(String xmlFile)
Imports BarCode properties from the xml-file specified and creates BarcodeGenerator instance.
Parameters:
Parameter | Type | Description |
---|---|---|
xmlFile | java.lang.String | The name of the file |
Returns: BarcodeGenerator - BarcodeGenerator instance
notify()
public final native void notify()
notifyAll()
public final native void notifyAll()
save(OutputStream stream, BarCodeImageFormat format)
public void save(OutputStream stream, BarCodeImageFormat format)
Save barcode image to stream in specific format.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.OutputStream | Output OutputStream. |
format | BarCodeImageFormat | Specifies the file format of the output image. |
save(String filename)
public void save(String filename)
Save barcode image to specific file.
Parameters:
Parameter | Type | Description |
---|---|---|
filename | java.lang.String | Path to save to. |
save(String filename, BarCodeImageFormat format)
public void save(String filename, BarCodeImageFormat format)
Save barcode image to specific file in specific format.
Parameters:
Parameter | Type | Description |
---|---|---|
filename | java.lang.String | Path to save to. |
format | BarCodeImageFormat | Specifies the file format of the output image. |
setBarcodeType(BaseEncodeType value)
public void setBarcodeType(BaseEncodeType value)
Barcode symbology type.
Parameters:
Parameter | Type | Description |
---|---|---|
value | BaseEncodeType |
setCodeText(byte[] codeBytes)
public void setCodeText(byte[] codeBytes)
Set codetext as sequence of bytes.
Parameters:
Parameter | Type | Description |
---|---|---|
codeBytes | byte[] | Bytes of codetext |
setCodeText(String value)
public void setCodeText(String value)
Text to be encoded.
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setCodeText(String codeText, Charset encoding)
public void setCodeText(String codeText, Charset encoding)
Encodes the Unicode codeText into a byte sequence using the specified encoding . UTF-8 is the most commonly used encoding. If the encoding supports it, the function automatically inserts a 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, 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 ``` SetCodeText ``` setting Unicode-encoded text for 2D barcodes using different encodings: //Encode QR Code text using UTF-8 with BOM BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.QR); gen.setCodeText("\u8eca\u7a2e\u540d", StandardCharsets.UTF_8; gen.save("barcode.png", BarCodeImageFormat.PNG); BarCodeReader reader = new BarCodeReader("barcode.png", DecodeType.QR); for(BarCodeResult result : reader.readBarCodes()) System.out.println("BarCode CodeText: " + result.getCodeText()); //Encode DataMatrix text using Shift-JIS (Japanese encoding) BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.DATA_MATRIX); Charset charset = Charset.forName("Shift_JIS"); gen.setCodeText("\u8eca\u7a2e\u540d", charset); gen.save("barcode.png", BarCodeImageFormat.PNG); BarCodeReader reader = new BarCodeReader("barcode.png", DecodeType.DATA_MATRIX); for(BarCodeResult result : reader.readBarCodes()) System.out.println("BarCode CodeText: " + result.getCodeText(charset));
Parameters:
Parameter | Type | Description |
---|---|---|
codeText | java.lang.String | CodeText string |
encoding | java.nio.charset.Charset | Applied encoding |
setCodeText(String codeText, Charset encoding, boolean insertBOM)
public void setCodeText(String codeText, Charset encoding, boolean insertBOM)
Encodes the Unicode codeText into a byte sequence using the specified encoding . UTF-8 is the most commonly used encoding. If the encoding supports it and insertBOM is set to true , the function includes a 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, 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 ``` SetCodeText ``` with or without a BOM for 2D barcodes. //Encode codetext using UTF-8 with BOM BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.QR); gen.setCodeText("\u8eca\u7a2e\u540d", StandardCharsets.UTF_8, true); gen.save("barcode.png", BarCodeImageFormat.PNG); BarCodeReader reader = new BarCodeReader("barcode.png", DecodeType.QR); for(BarCodeResult result : reader.readBarCodes()) System.out.println("BarCode CodeText: " + result.getCodeText()); //Encode codetext using UTF-8 without BOM BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.QR); gen.setCodeText("\u8eca\u7a2e\u540d", StandardCharsets.UTF_8, false); gen.save("barcode.png", BarCodeImageFormat.PNG); BarCodeReader reader = new BarCodeReader("barcode.png", DecodeType.QR); for(BarCodeResult result : reader.readBarCodes()) System.out.println("BarCode CodeText: " + result.getCodeText());
Parameters:
Parameter | Type | Description |
---|---|---|
codeText | java.lang.String | CodeText string |
encoding | java.nio.charset.Charset | Applied encoding |
insertBOM | boolean | 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 true , the BOM is added; if false , the BOM is omitted even if the encoding normally uses one. |
toString()
public String toString()
Returns: java.lang.String
wait()
public final void wait()
wait(long arg0)
public final native void wait(long arg0)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | long |
wait(long arg0, int arg1)
public final void wait(long arg0, int arg1)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | long | |
arg1 | int |