Tagliatti / NetBarcode

Barcode generation library written in C# and .NET Standard 2
MIT License
337 stars 68 forks source link

128 barcode are not accurate #24

Open liviupopovici123 opened 3 years ago

liviupopovici123 commented 3 years ago

Hi, I've tried to encode "10500400412728169" using 128 and 128C. They are the same. I've tried to decode using an online tool and it decodes as "010500400412728169". This is the generated barcode image And this is the correct one that should be generated image001 Any thoughts on this?

Tagliatti commented 3 years ago

Thanks for reporting, I'm investigating the issue.

Vandersteen commented 3 years ago

It appears to be happening when having an 'uneven' number of numbers:

Generates a correct barcode:

Generates a barcode prefixed with 0:

Which appears to be coming from: https://github.com/Tagliatti/NetBarcode/blob/ad1402ab4bf5cf18e251be58ae9ea55d1e1455ab/NetBarcode/Types/Code128.cs#L255

I don't have knowledge of the CODE128 barcode structure so this might be correct behaviour

trajekolus commented 3 years ago

@Vandersteen I think it is correct behavior because Code128 automatically switch between the three subsets (A, B, and C) to code the data in the shortest form. And if subset C is picked, a leading "0" is added if there are an odd number of digits in the code as you also found.

Specifying Code128B specifically solved the issue for me.