Search code examples
javabarcodebarcode-scannerbarcode4j

How to generate a valid EAN13 barcode in Java?


I want to generate a EAN13 barcode using java but I cannot find a library that generates this number. I found the library barcode4j, a text library but it only generates the image. My problem now is that to make the number itself valid. (I can check it later online to see if its checksum is correct).


Solution

  • Don't generate the whole thing. Generate the first numbers, and calculate the checksum.

    For example, if you were creating this existing EAN: 7025446116002, you'd only generate 702544611600, and then generate the last digit yourself.

    Now the question is how do you generate that number? The answer can be found here

    You said you already had the barcode generator bit working, so this should be fine.