lindell / JsBarcode

Barcode generation library written in JavaScript that works in both the browser and on Node.js
http://lindell.me/JsBarcode
MIT License
5.45k stars 1.1k forks source link

CODE128 barcode displays incorrectly #316

Open jordan-stlpro opened 4 years ago

jordan-stlpro commented 4 years ago

image

As you can see from the image, the top/black barcode is one generated using JsBarcode. The bottom/red one is what I'm actually trying to generate. They are both CODE128, but it seems that the CODE128 Auto setting slightly misrepresents a small portion of the barcode (indicated by the green arrows). The project BWIP-JS generates it as expected, but I'd prefer to use JsBarcode instead, as I've been using it for a little over a year now. What would I need to do to solve the minor discrepancy in the generated barcode?

diemus commented 4 years ago

thanks! BWIP-JS works fine

vijendra commented 4 years ago

Any suggestion on this please. Even I am getting little difference, comparing it to the one printed using raw PRN file or through some other online tools.

wodin commented 4 years ago

These barcodes both represent the same value.

The difference is because the number is not an even number of digits. So the first 18 digits are encoded using CODE 128C and the last digit needs to be encoded using CODE 128A or CODE 128B. The choice of whether to use 128A or 128B is arbitrary because character being encoded (1) is a single symbol in both. The symbol to switch to 128A is 11101011110. This is what the "Generated" barcode is using. The symbol to switch to 128B is 10111101110. This is what the "Expected" barcode is using. The symbol for 1 is the same in both 128A and 128B (10011100110), so both barcodes look the same there. The next symbol is the checksum. Because one barcode is using the 128A symbol before the last 1 digit and the other is using the 128B symbol, the checksum is different. That is why the barcodes differ after the 1 digit. The stop symbol and final bar at the end are the same for both again.

So if you scan either of these barcodes you will get the same value.