I am using zxing with App inventor 2. If I encode a 6 digit number into an ITF barcode the zxing android scanner works OK. However if I create ITF barcodes from 2 or 4 digits the barcode is shorter and it doesn't scan . For my app I prefer the barcode to be as short as possible. Please help Thanks David
2 Answers
ITF has no required checksum, so it's problematic to allow it to scan for very short ITF codes. It makes very likely to see them as phantom reads in non-barcode images. The minimum ITF length that's accepted is 6 characters. You can override this, but if you do, you need to use a checksum and verify it in your code. It's probably not a great choice of format.
As Sean already answered, ITF format has no checksum, so the authors of ZXing decided to support minimum 6 character barcodes, to avoid high "false positive" rate, i.e. the situation where shorter barcodes would be detected inside the longer ones.
You can see that clearly from the ZXing source code. Minimum allowed length is 6.
Authors also advise that you add checksum characters in the ITF barcode, to get more confidence in the obtained result.
This is the best solution for your case: on the side where you generate the barcode, add additional 2 characters, as check digits, to obtain 6-digit value. The best approach for generating check digits would be to use MOD-97-10 ISO 7064 standard, which is commonly used for protecting IBAN numbers. ZXing's ITF scanner can handle 6 character barcodes very well, and you can also verify the obtained check digits for extra confidence in the results.
If that's not applicable in your case, you can edit the ZXing source code that was linked above, add the ability to scan ITF barcodes of length 2 and 4, and integrate this custom build in your app.