Search code examples
javags1-ai-syntaxgs1-qr-code

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


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?


Solution

  • 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 ;)