Set Barcode Checksum
Set Barcode Checksum
Checksums help detect data errors. Their behavior depends on the selected symbology.
Enable an optional checksum
Some symbologies allow a checksum to be enabled or disabled.
BarcodeGenerator generator = new BarcodeGenerator(
EncodeTypes.INTERLEAVED_2_OF_5,
"123456"
);
generator.getParameters().getBarcode()
.setChecksumEnabled(EnableChecksum.YES);
The reader can be configured to validate the checksum through ChecksumValidation.ON, OFF, or DEFAULT.
For Interleaved 2 of 5, enabling the checksum may append a Mod10 digit and may also cause a leading zero to be added so the encoded digit count remains valid for the symbology.
Mandatory check digits
EAN, UPC, Code 128, Code 93, GS1-128, and several logistics symbologies require a check digit or checksum as part of their specification. For example, EAN-13 consists of 12 data digits plus one check digit.
BarcodeGenerator generator = new BarcodeGenerator(
EncodeTypes.EAN_13,
"590123412345"
);
The generated and decoded value is 5901234123457.
See the EAN-13 standard overview, Code 128 standard overview, and Code 39 standard overview.
Do not assume that EnableChecksum.NO can disable a checksum required by the barcode standard. Mandatory-checksum symbologies may reject such a configuration.
Complete example
View EnforcedChecksumExamples.java
View OptionalChecksumExamples.java
set