public final class BarcodeGenerator
extends java.lang.Object
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");
Constructor and Description |
---|
BarcodeGenerator(BaseEncodeType type)
Creates an instance of BarcodeGenerator.
|
BarcodeGenerator(BaseEncodeType type,
java.lang.String codeText)
Creates an instance of BarcodeGenerator.
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Clean up any resources being used.
|
boolean |
exportToXml(java.io.OutputStream xml)
Exports BarCode properties to the xml-stream specified
|
boolean |
exportToXml(java.lang.String xmlFile)
Exports BarCode properties to the xml-file specified
|
java.awt.image.BufferedImage |
generateBarCodeImage()
Generate the barcode image under current settings.
|
BaseEncodeType |
getBarcodeType()
Barcode symbology type.
|
java.lang.String |
getCodeText()
Text to be encoded.
|
BaseGenerationParameters |
getParameters()
Generation parameters.
|
static BarcodeGenerator |
importFromXml(java.io.InputStream xml)
Imports BarCode properties from the xml-stream specified and creates BarcodeGenerator instance.
|
static BarcodeGenerator |
importFromXml(java.lang.String xmlFile)
Imports BarCode properties from the xml-file specified and creates BarcodeGenerator instance.
|
void |
save(java.io.OutputStream stream,
BarCodeImageFormat format)
Save barcode image to stream in specific format.
|
void |
save(java.lang.String filename)
Save barcode image to specific file.
|
void |
save(java.lang.String filename,
BarCodeImageFormat format)
Save barcode image to specific file in specific format.
|
void |
setBarcodeType(BaseEncodeType value)
Barcode symbology type.
|
void |
setCodeText(byte[] codeBytes)
Set codetext as sequence of bytes.
|
void |
setCodeText(java.lang.String value)
Text to be encoded.
|
void |
setCodeText(java.lang.String codeText,
java.nio.charset.Charset encoding)
Encodes codetext with byte order mark (BOM), using specified encoding.
|
void |
setCodeText(java.lang.String codeText,
java.nio.charset.Charset encoding,
boolean insertBOM)
Encodes codetext with optional byte order mark (BOM) insertion, using specified encoding:
like UTF8, UTF16, UTF32, e.t.c.
|
public BarcodeGenerator(BaseEncodeType type)
Creates an instance of BarcodeGenerator.
type
- Barcode symbology type. Use EncodeTypes
class to setup a symbology.public BarcodeGenerator(BaseEncodeType type, java.lang.String codeText)
Creates an instance of BarcodeGenerator.
type
- Barcode symbology type. Use EncodeTypes
class to setup a symbology.codeText
- Text to be encoded.public BaseGenerationParameters getParameters()
Generation parameters.
public BaseEncodeType getBarcodeType()
Barcode symbology type.
public void setBarcodeType(BaseEncodeType value)
Barcode symbology type.
public java.lang.String getCodeText()
Text to be encoded.
public void setCodeText(java.lang.String value)
Text to be encoded.
public void setCodeText(byte[] codeBytes)
Set codetext as sequence of bytes.
codeBytes
- Bytes of codetextpublic void setCodeText(java.lang.String codeText, java.nio.charset.Charset encoding)
Encodes codetext with byte order mark (BOM), using specified encoding. This sample shows how to use SetCodeText with 1D and 2D barcodes
BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.CODE_128); gen.setCodeText("123ABCD", StandardCharsets.US_ASCII); gen.save("barcode.png", BarCodeImageFormat.PNG); BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.QR); gen.setCodeText("123ABCD", StandardCharsets.ISO_8859_1, true); gen.save("barcode.png", BarCodeImageFormat.PNG); BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.QR); gen.setCodeText("123ABCD", Encoding.UTF_8, false); gen.save("barcode.png", BarCodeImageFormat.PNG);
codeText
- CodeText stringencoding
- Applied encodingpublic void setCodeText(java.lang.String codeText, java.nio.charset.Charset encoding, boolean insertBOM)
Encodes codetext with optional byte order mark (BOM) insertion, using specified encoding: like UTF8, UTF16, UTF32, e.t.c. 1D barcodes should use Encoding ASCII or ISO/IEC 8859-1. 2D barcodes should use Encoding UTF8. Detailed description you can find in the @see documentation
This sample shows how to use setCodeTextBarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.CODE_128); gen.setCodeText("123ABCD", StandardCharsets.ISO_8859_1, true); gen.save("barcode.png", BarCodeImageFormat.PNG); BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.CODE_128); gen.setCodeText("123ABCD", StandardCharsets.UTF_8, false); gen.save("barcode.png", BarCodeImageFormat.PNG);
codeText
- CodeText stringencoding
- Applied encodinginsertBOM
- flag indicates insertion of the Encoding byte order mark (BOM). In case, the Encoding requires byte order mark (BOM) insertion: like UTF8,
UTF16, UTF32, e.t.c. and flag is set to true, the BOM is added, in case of setting flag to false, the BOM insertion is ignored.public java.awt.image.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);
Bitmap
.public void save(java.io.OutputStream stream, BarCodeImageFormat format) throws java.io.IOException
Save barcode image to stream in specific format.
stream
- Output OutputStream
.format
- Specifies the file format of the output image.java.io.IOException
public void save(java.lang.String filename, BarCodeImageFormat format) throws java.io.IOException
Save barcode image to specific file in specific format.
filename
- Path to save to.format
- Specifies the file format of the output image.java.io.IOException
public void save(java.lang.String filename) throws java.io.IOException
Save barcode image to specific file.
filename
- Path to save to.java.io.IOException
public boolean exportToXml(java.lang.String xmlFile)
Exports BarCode properties to the xml-file specified
xmlFile
- The name of the fileReturns <b>True</b>
in case of success; <b>False</b>
Otherwise
public boolean exportToXml(java.io.OutputStream xml) throws java.io.IOException
xml
- The xml-streamjava.io.IOException
public static BarcodeGenerator importFromXml(java.lang.String xmlFile)
Imports BarCode properties from the xml-file specified and creates BarcodeGenerator instance.
xmlFile
- The name of the filepublic static BarcodeGenerator importFromXml(java.io.InputStream xml)
xml
- The xml-streampublic void dispose()
Clean up any resources being used.