How bar codes are generated
Posted on 2005-04-20
Well, it is half a question, half a sharing of knowledge. I have to implement in my code the bar code generation, but not using 3rd party componenets, I needed it to be made by MY code, as finally the bar code ended up as vector images, not bitmaps.
The fact is that I was unable to find the algorithms to generate the bars in any google search! May be it is short of industrial secret... finally, I found a partial reference on how to do it, and checking the bars I generated with real examples, I managed to complete the algorithm to be able to produce 100% correct bar codes... on one type only, as there existe docens of types!
The format I worked out is called UPCA, and is the tipical one in the food pakages. But it only allows to represent 12 digits (0 to 9), no letters or punctuations.
I would like to get more format especifications so I can generate other formats.
In the meanwhile, I will post as an answer to this question, the internal workings of this format, so it is not a "secret" anymore. I haven't read in any page that the algorithm is copyrighted so I suppose it is not ilegal to publish it. If it is, please let me know.
Links are wellcome as long as they explain the way you construct the bars, not only the checksums, as this is the easy part (most of the format use the same algorithm to compute checksums).