Read GS1 QRcode and get the data without the check digit character

878 views Asked by At

I am trying to read a QRCode in GS1 format. When I built the QR Code for the identifier (01) with the value 0100145074001, my QRCode generator adds in the end a check digit 9. So the result is:

01001450740019

Now, I try to parse this QRCode in my Java Program. I found this library gs1Utils and when I execute the following :

String brc = "0101001450740019";
ElementStrings.ParseResult result = ElementStrings.parse(brc); 
System.out.println("CONTAINED_GTIN= " + result.getString(ApplicationIdentifier.CONTAINED_GTIN));

I get CONTAINED_GTIN= 01001450740019. However, I want to read only the 0100145074001 and not the check digit.

I don't know if this certain library is not working well, or I have misunderstood how the GS1 works. My question is: How can I get the value of a GS1 QRcode in Java without the check digit?

3

There are 3 answers

0
Michael Angelos Simos On BEST ANSWER

You can jsut read the first characters, as the specific formatting originates from your QRCode generator.

Using result.getString(ApplicationIdentifier.CONTAINED_GTIN).substring(0, 13); Should do the trick

However, the check-digit can be used for a validation check. It's worth adding a:

CheckDigit.validate(ApplicationIdentifier.CONTAINED_GTIN)

line somewhere, for avoiding input issues in future ;)

0
yaylitzis On

The library I used (gs1Utils) is working fine.

The biggest misconception that I had, was that the GS1 barcode prototype adds check digits in the end, in all Application Identifiers (AI). But it doesn't!

In my case, the GTIN has AI 01 and the check digit is calculated based on this simple algorithm:

enter image description here

So the code 0100145074001 has check digit 9 and the :

result.getString(ApplicationIdentifier.CONTAINED_GTIN)

returns 01001450740019.

All my codes have fix length (13). So, the answer to my question is to read the first 13 characters...

String myCode = result.getString(ApplicationIdentifier.CONTAINED_GTIN).substring(0, 13);
0
I'm_Pratik On

You can use String.substring method to get the required character from the given String

System.out.println("CONTAINED_GTIN= " + result.getString(ApplicationIdentifier.CONTAINED_GTIN).substring(0, 13));