Matrix 2 of 5
- 2 minutes to read
Matrix 2 of 5 is a low-density, numeric-only linear barcode symbology. It encodes information using bars only, while spaces have a fixed width and serve as separators.

Refer to the following page for additional information: https://en.wikipedia.org/wiki/Matrix_2_of_5
Configure Matrix 2 of 5 Settings
Use the Matrix2of5Options class to configure Matrix 2 of 5 barcode settings.
The following code snippet creates a Matrix 2 of 5 barcode and customizes its encoding parameters:
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 {
Matrix2of5Options options = new Matrix2of5Options();
options.setCalculateChecksum(true);
options.setWideNarrowRatio(3);
options.setPadding(new Padding(10));
options.setShowText(true);
options.setWidth(600);
Path outputDir = Path.of("output");
Files.createDirectories(outputDir);
try (FileOutputStream fileStream = new FileOutputStream(
outputDir.resolve("matrix2of5.png").toFile());
BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
barcodeGenerator.export(
"12345670",
fileStream,
DXImageFormat.getPng());
}
}
}
Fluent API
Use the Matrix2of5OptionsBuilder class to configure Matrix 2 of 5 barcode settings with the Fluent API.
The following code snippet creates a Matrix 2 of 5 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 {
Matrix2of5Options options = Matrix2of5OptionsBuilder.create()
.withCalculateChecksum(true)
.withWideNarrowRatio(3)
.withPadding(new Padding(10))
.withShowText(true)
.withWidth(600)
.build();
Path outputDir = Path.of("output");
Files.createDirectories(outputDir);
try (FileOutputStream fileStream = new FileOutputStream(
outputDir.resolve("matrix2of5.png").toFile());
BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
barcodeGenerator.export(
"12345670",
fileStream,
DXImageFormat.getPng());
}
}
}
See Also