Something wrong with my barcode (Code 128)
It was easy to generate a 3 of 9 barcode using Font()
Font f = new Font("Free 3 of 9", 80); this.Font = f; Label l = new Label(); l.Text = "*STACKOVERFLOW*"; l.Size = new System.Drawing.Size(800, 600); this.Controls.Add(l); this.Size = new Size(800, 600);
Its working. I see the barcode and Im able to scan it. Now I would like to use something else, like Code 128 For that I need to install the Font (done) and just change
Font f = new Font("Free 3 of 9", 80); to Font f = new Font("Code 128", 80);
After that I see a barcode on my window. The problem is that Im not able to scan that. And I think thats because I dont use the right start and stop tag for the barcode. As I understood there have to be always a start/stop char or whatever. For 3 of 9 ist the * for Code 128 im not sure. On wiki there is Start Code A so I tried
Font f = new Font("<Start Code A>test<Stop>", 80);, Font f = new Font("<Start Code A>test<Stop Code A>", 80); and so on... Im not able to scan the output. Because the scanner cannot find the start and stop char. Any ideas? Thank you
Code 128 can be represented with a font totally fine. It's trickier than 3 of 9 though because you have to include a checksum character at the end which needs to be dynamically computed based on the content of the barcode. There are also 3 different versions which each have a different start char.
In other words the barcode needs to be laid out like:
[start char][barcode][checksum][stop char]
The benefit of code128 is that it is much more concise than 3 of 9.
This page helped me work out the algorithm to compute my checksums.
A very general overview of the algorithm is:
Each character of the barcode gets a specific value assigned to it depending on what the character is and where it is located in the barcode.
All of the values in 1) above are added together.
Get the modulus 103 value of the total in 2) above.
In most cases, the checksum char will be the ASCII code for: (modulus value plus 32) as determined in 3) above.
You may notice that my start and stop chars in my example (š, œ) don't seem to match up with the ones shown on the linked page. If I remember I think it was because I had some non-standard code128 font and these chars translated to the correct ones.
I checked back in my documentation. It looks like I got the font from right here. With that font specifically and using the algorithm above, I just made a code128b barcode for test which came out to štestwœ, it scanned fine. Your checksum algorithm seems to be working fine because we both have w but it looks like your start and stop codes are off if you are getting: ÌtestwÎ.
I made a point to look for the same barcode font that I am using because I have a feeling that different brands of code128 fonts may implement different characters to represent the start and stop barcodes.
Are you creating the correct checksum character?
Have a look at this page to see how to calculate the checksum
For an alternative have a look at the following link - this allows you to create barcode bitmaps:
Looking at Wikipedia page for Barcode128, I think you should use ASCII codes 208-210 to delimit a block, according to Bar Code Widths paragraph and table.