BarcodeGenerator Class
Creates barcodes and exports them to image streams, DXImage objects, and PDF documents.
Declaration
public class BarcodeGenerator extends JavaObject implements IDisposable
Remarks
| Method | Use when you need |
|---|---|
| BarcodeGenerator.export() | To write barcode image data directly to an OutputStream or WritableByteChannel. |
| BarcodeGenerator.exportToImage() | To create a barcode image in memory as a DXImage object. |
| BarcodeGenerator.exportToPdf() | To write barcode content directly to a PDF document. |
Barcode export methods include overloads for the following input and output data types:
- Input
String textString text, Charset encodingbyte[] binaryData
- Output
OutputStreamWritableByteChannel- DXImage
- Optional parameter
- DXImageFormat for image export
Note
If you omit the image format or pass null, the API uses PNG.
Refer to the Export Barcodes to Images and PDF help topic for additional information.
Examples
Export to PDF
The following code snippet exports a barcode to a PDF document:
import com.devexpress.docs.barcode.*;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
EAN128Options options = new EAN128Options();
options.setShowText(true);
options.setWidth(600);
Path outputDir = Path.of("output");
Files.createDirectories(outputDir);
try (FileOutputStream stream = new FileOutputStream(
outputDir.resolve("ean128.pdf").toFile());
BarcodeGenerator generator = new BarcodeGenerator(options)) {
// Export the barcode to PDF.
generator.exportToPdf(
"(01)09506000134352(17)260630(10)ABC123",
stream);
}
}
}
Export to Image (PNG)
The following code snippet exports a QR Code to a PNG file:
import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
QRCodeOptions options = new QRCodeOptions();
options.setModuleSize(6);
options.setShowText(false);
Path outputDir = Path.of("output");
Files.createDirectories(outputDir);
try (FileOutputStream stream = new FileOutputStream(
outputDir.resolve("qr-code.png").toFile());
BarcodeGenerator generator = new BarcodeGenerator(options)) {
// Export the barcode as a PNG image.
generator.export(
"https://www.devexpress.com",
stream,
DXImageFormat.getPng());
}
}
}
Implements
Inherited Members
Inheritance
BarcodeGenerator(BarcodeOptions options)
Initializes a new instance of the BarcodeGenerator class with specified barcode options.
Declaration
public BarcodeGenerator(BarcodeOptions options)
Parameters
| Name | Type | Description |
|---|---|---|
| options | BarcodeOptions | Barcode options. |
Methods
close() Method
Closes the BarcodeGenerator and releases all internal resources.
Declaration
public void close()
export(byte[] binaryData, OutputStream stream, DXImageFormat format) Method
Encodes the specified binary data into a barcode and writes the generated image in the specified format to the specified stream.
Declaration
public void export(byte[] binaryData, OutputStream stream, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. The value must conform to barcode symbology rules. |
| stream | OutputStream | The output stream where the generated barcode image is written. |
| format | DXImageFormat | The output image format for the generated barcode. If |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
export(byte[] binaryData, OutputStream stream) Method
Encodes the specified binary data into a barcode and writes the generated image to the specified stream.
Declaration
public void export(byte[] binaryData, OutputStream stream)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. The value must conform to barcode symbology rules. |
| stream | OutputStream | The output stream where the generated barcode image is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
export(byte[] binaryData, WritableByteChannel channel, DXImageFormat format) Method
Encodes the specified binary data into a barcode and writes the generated image in the specified format to the specified writable byte channel.
Declaration
public void export(byte[] binaryData, WritableByteChannel channel, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. The value must conform to barcode symbology rules. |
| channel | WritableByteChannel | The writable byte channel where the generated barcode image is written. |
| format | DXImageFormat | The output image format for the generated barcode. If |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
export(byte[] binaryData, WritableByteChannel channel) Method
Encodes the specified binary data into a barcode and writes the generated image to the specified writable byte channel.
Declaration
public void export(byte[] binaryData, WritableByteChannel channel)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. The value must conform to barcode symbology rules. |
| channel | WritableByteChannel | The writable byte channel where the generated barcode image is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
export(String text, Charset encoding, OutputStream stream, DXImageFormat format) Method
Encodes the specified text into a barcode using the specified character encoding and writes the generated image in the specified format to the specified stream.
Declaration
public void export(String text, Charset encoding, OutputStream stream, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| encoding | Charset | The character encoding used to convert the specified text to binary data. |
| stream | OutputStream | The output stream where the generated barcode image is written. |
| format | DXImageFormat | The output image format for the generated barcode. If |
export(String text, Charset encoding, OutputStream stream) Method
Encodes the specified text into a barcode using the specified character encoding and writes the generated image to the specified stream.
Declaration
public void export(String text, Charset encoding, OutputStream stream)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| encoding | Charset | The character encoding used to convert the specified text to binary data. |
| stream | OutputStream | The output stream where the generated barcode image is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
export(String text, Charset encoding, WritableByteChannel channel, DXImageFormat format) Method
Encodes the specified text into a barcode using the specified character encoding and writes the generated image in the specified format to the specified writable byte channel.
Declaration
public void export(String text, Charset encoding, WritableByteChannel channel, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| encoding | Charset | The character encoding used to convert the specified text to binary data. |
| channel | WritableByteChannel | The writable byte channel where the generated barcode image is written. |
| format | DXImageFormat | The output image format for the generated barcode. If |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
export(String text, Charset encoding, WritableByteChannel channel) Method
Encodes the specified text into a barcode using the specified character encoding and writes the generated image to the specified writable byte channel.
Declaration
public void export(String text, Charset encoding, WritableByteChannel channel)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| encoding | Charset | The character encoding used to convert the specified text to binary data. |
| channel | WritableByteChannel | The writable byte channel where the generated barcode image is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
export(String text, OutputStream stream, DXImageFormat format) Method
Encodes the specified text into a barcode and writes the generated image in the specified format to the specified stream.
Declaration
public void export(String text, OutputStream stream, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| stream | OutputStream | The output stream where the generated barcode image is written. |
| format | DXImageFormat | The output image format for the generated barcode. If |
export(String text, OutputStream stream) Method
Encodes the specified text into a barcode and writes the generated image to the specified stream.
Declaration
public void export(String text, OutputStream stream)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| stream | OutputStream | The output stream where the generated barcode image is written. |
Remarks
The following code snippet creates a UPC-A barcode, customizes its encoding parameters, and writes the generated image to an output stream. The API uses PNG as the default image format.
import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import com.devexpress.system.drawing.*;
import com.devexpress.docs.Padding;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
UPCAOptions options = new UPCAOptions();
options.setPadding(new Padding(10));
options.setModuleSize(10);
options.setShowText(true);
options.setWidth(600);
options.setHeight(200);
Path outputDir = Path.of("output");
Files.createDirectories(outputDir);
try (FileOutputStream fileStream = new FileOutputStream(
outputDir.resolve("upc-a.png").toFile());
BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
barcodeGenerator.export(
"72527273070",
fileStream);
}
}
}
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
export(String text, WritableByteChannel channel, DXImageFormat format) Method
Encodes the specified text into a barcode and writes the generated image in the specified format to the specified writable byte channel.
Declaration
public void export(String text, WritableByteChannel channel, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| channel | WritableByteChannel | The writable byte channel where the generated barcode image is written. |
| format | DXImageFormat | The output image format for the generated barcode. If |
Remarks
The following code snippet creates a QR Code barcode and customizes its encoding parameters with the Fluent API:
import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import com.devexpress.system.drawing.*;
import com.devexpress.docs.Padding;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
byte[] logoBytes = Files.readAllBytes(Path.of("images/devexpress-logo.png"));
try (DXImage logo = DXImage.fromStream(new ByteArrayInputStream(logoBytes))) {
// Customize QR Code frame parameters.
RectangleQRFrameOptions frameOptions = new RectangleQRFrameOptions();
frameOptions.setPadding(new Padding(10));
frameOptions.setFrameColor(Color.getOrange());
frameOptions.setFrameWidth(10);
frameOptions.setText("DevExpress");
frameOptions.setCornerRadius(10);
frameOptions.setTextAlignment(QRFrameTextAlignment.CENTER);
frameOptions.setTextColor(Color.getBlack());
frameOptions.setTextPosition(QRFrameTextPosition.BOTTOM);
// Customize QR Code parameters.
QRCodeOptions options = QRCodeOptionsBuilder.create()
.withErrorCorrectionLevel(QRCodeErrorCorrectionLevel.H)
.withCompactionMode(QRCodeCompactionMode.AUTO)
.withVersion(QRCodeVersion.VERSION_10)
.withIncludeQuietZone(true)
.withFrameOptions(frameOptions)
.withLogo(logo)
.withPadding(new Padding(10))
.withModuleSize(10)
.withShowText(false)
.build();
Path outputDir = Path.of("output");
Files.createDirectories(outputDir);
try (FileOutputStream fileStream = new FileOutputStream(
outputDir.resolve("qrcode.png").toFile());
BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
barcodeGenerator.export(
"https://www.devexpress.com",
fileStream,
DXImageFormat.getPng());
}
}
}
}
export(String text, WritableByteChannel channel) Method
Encodes the specified text into a barcode and writes the generated image to the specified writable byte channel.
Declaration
public void export(String text, WritableByteChannel channel)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| channel | WritableByteChannel | The writable byte channel where the generated barcode image is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToImage(byte[] binaryData, DXImageFormat format) Method
Encodes the specified binary data into a barcode and returns the generated image in the specified format.
Declaration
public DXImage exportToImage(byte[] binaryData, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. The value must conform to barcode symbology rules. |
| format | DXImageFormat | The output image format for the generated barcode. If |
Returns
| Type | Description |
|---|---|
| DXImage | The generated barcode image. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToImage(byte[] binaryData) Method
Encodes the specified binary data into a barcode and returns the generated image.
Declaration
public DXImage exportToImage(byte[] binaryData)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. The value must conform to barcode symbology rules. |
Returns
| Type | Description |
|---|---|
| DXImage | The generated barcode image. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToImage(String text, Charset encoding, DXImageFormat format) Method
Encodes the specified text into a barcode using the specified character encoding and returns the generated image in the specified format.
Declaration
public DXImage exportToImage(String text, Charset encoding, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| encoding | Charset | The character encoding used to encode the text into the barcode. |
| format | DXImageFormat | The output image format for the generated barcode. If |
Returns
| Type | Description |
|---|---|
| DXImage | The generated barcode image. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToImage(String text, Charset encoding) Method
Encodes the specified text into a barcode using the specified character encoding and returns the generated image.
Declaration
public DXImage exportToImage(String text, Charset encoding)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| encoding | Charset | The character encoding used to encode the text into the barcode. |
Returns
| Type | Description |
|---|---|
| DXImage | The generated barcode image. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToImage(String text, DXImageFormat format) Method
Encodes the specified text into a barcode and returns the generated image in the specified format.
Declaration
public DXImage exportToImage(String text, DXImageFormat format)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| format | DXImageFormat | The output image format for the generated barcode. If |
Returns
| Type | Description |
|---|---|
| DXImage | The generated barcode image. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToImage(String text) Method
Encodes the specified text into a barcode and returns the generated image.
Declaration
public DXImage exportToImage(String text)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
Returns
| Type | Description |
|---|---|
| DXImage | The generated barcode image. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToPdf(byte[] binaryData, OutputStream stream) Method
Encodes the specified binary data into a barcode and writes the generated PDF document to the specified stream.
Declaration
public void exportToPdf(byte[] binaryData, OutputStream stream)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. The value must conform to barcode symbology rules. |
| stream | OutputStream | The output stream where the generated PDF document is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToPdf(byte[] binaryData, WritableByteChannel channel) Method
Encodes the specified binary data into a barcode and writes the generated PDF document to the specified writable byte channel.
Declaration
public void exportToPdf(byte[] binaryData, WritableByteChannel channel)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. The value must conform to barcode symbology rules. |
| channel | WritableByteChannel | The writable byte channel where the generated PDF document is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToPdf(String text, Charset encoding, OutputStream stream) Method
Encodes the specified text into a barcode using the specified character encoding and writes the generated PDF document to the specified stream.
Declaration
public void exportToPdf(String text, Charset encoding, OutputStream stream)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| encoding | Charset | The character encoding used to encode the text into the barcode. |
| stream | OutputStream | The output stream where the generated PDF document is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToPdf(String text, Charset encoding, WritableByteChannel channel) Method
Encodes the specified text into a barcode using the specified character encoding and writes the generated PDF document to the specified writable byte channel.
Declaration
public void exportToPdf(String text, Charset encoding, WritableByteChannel channel)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| encoding | Charset | The character encoding used to encode the text into the barcode. |
| channel | WritableByteChannel | The writable byte channel where the generated PDF document is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToPdf(String text, OutputStream stream) Method
Encodes the specified text into a barcode and writes the generated PDF document to the specified stream.
Declaration
public void exportToPdf(String text, OutputStream stream)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| stream | OutputStream | The output stream where the generated PDF document is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
exportToPdf(String text, WritableByteChannel channel) Method
Encodes the specified text into a barcode and writes the generated PDF document to the specified writable byte channel.
Declaration
public void exportToPdf(String text, WritableByteChannel channel)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. The value must conform to barcode symbology rules. |
| channel | WritableByteChannel | The writable byte channel where the generated PDF document is written. |
Remarks
Refer to the following help topic for additional information: Export Barcodes to Images and PDF.
getOptions() Method
Gets barcode configuration options.
Declaration
public BarcodeOptions getOptions()
Returns
| Type | Description |
|---|---|
| BarcodeOptions | Barcode configuration options. |
Remarks
Refer to the following help topic for additional information: Barcode Options.
print(byte[] binaryData, PrintOptions printOptions) Method
This API is reserved for future use.
Declaration
public void print(byte[] binaryData, PrintOptions printOptions)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. |
| printOptions | com.devexpress.docs.barcode.PrintOptions | (Optional) The print options to use. If null, the default print settings are used. |
print(byte[] binaryData) Method
This API is reserved for future use.
Declaration
public void print(byte[] binaryData)
Parameters
| Name | Type | Description |
|---|---|---|
| binaryData | byte[] | The binary data to encode as a barcode. |
print(String text, Charset encoding, PrintOptions printOptions) Method
This API is reserved for future use.
Declaration
public void print(String text, Charset encoding, PrintOptions printOptions)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. |
| encoding | Charset | The character encoding. |
| printOptions | com.devexpress.docs.barcode.PrintOptions | The print options to use. |
print(String text, Charset encoding) Method
This API is reserved for future use.
Declaration
public void print(String text, Charset encoding)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. |
| encoding | Charset | The character encoding. |
print(String text, PrintOptions printOptions) Method
This API is reserved for future use.
Declaration
public void print(String text, PrintOptions printOptions)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. |
| printOptions | com.devexpress.docs.barcode.PrintOptions | (Optional) The print options to use. If null, the default print settings are used. |
print(String text) Method
This API is reserved for future use.
Declaration
public void print(String text)
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. |
setOptions(BarcodeOptions value) Method
Sets barcode configuration options.
Declaration
public void setOptions(BarcodeOptions value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | BarcodeOptions | Barcode configuration options. |
Remarks
Refer to the following help topic for additional information: Barcode Options.