There's a hole in my barcode!!! And other common pitfalls with Code 39 barcodes
Code 39 is one of the most popular types of bar code and considered one of the easiest to work with, but there are a number of pitfalls that can catch you out if you’re not careful. This article aims to give you an overview of how Code 39 works and what to watch out for when creating your own.
So how does it work?
Each character in a Code 39 bar code is represented by 5 bars and 4 spaces – that’s 9 elements in total, of which 3 of are wide and 6 are narrow. So 3 out of 9 elements in each character are wide – hence Code 39. There are only 2 widths of bar and space – narrow or wide and the total number of bars should be divisible by 5. Also, all Code 39 bar codes must start and finish with the asterisk (*) character.
Here’s a good one…
Pitfall 1: Missing start and stop characters
Bar codes may all look like a series of parallel bars but each type has its own signature and in the case of Code 39 this is the start and stop character or asterisk (*). It’s easy to spot once you have your eye in. The first and last 5 bars of the bar code should match the following pattern:
narrow, narrow, wide, wide, narrow
When we get sent a Code 39 bar code that won’t decode the first thing we do is look at these bars to see if they match the correct pattern. This one is the same bar code as above except that it’s missing the start and stop sequence. It’s what you would get if you typed in F002736 rather than *F002736* and although the bars and spaces for the F and other characters are all correct it is not a valid Code 39 bar code because of the missing start and stop sequences.
Why bother with a start and stop character? The obvious answer is because that’s how it is but it’s more interesting to note that without a fixed start and stop character a Code 39 bar code would read with 2 different values – left to right and right to left. This would be confusing so that’s why we should stick with convention and use the asterisk.
Pitfall 2: The extra space after the stop character
So you’ve downloaded and installed your Code 39 font. You type in some text and remember to include the asterisk at the start and end. You mark the text and select the Code 39 font and hey presto the last 5 bars are not the same as the first 5 bars. What’s going on?
Some word processors treat spaces just like any other character and when you mark text you often include the trailing space after a word. Since the space character is a perfectly valid Code 39 character with its own sequence of bars and spaces this means that you get some unwanted extra stuff at the end of your bar code. You can spot this by looking at the penultimate set of 5 bars and check to see if they match the narrow, narrow, wide, wide, narrow pattern that represents the asterisk (or stop) character. The solution is to take extra care when marking text and don’t include the space.
Most modern word processors don’t treat spaces in this way but this has a flip side and can lead to……
Pitfall 3: There’s a hole in my bar code!
You want to include a space in the text for your bar code but all you get is a hole in the middle rather than the bars and spaces that represent a space. This is because modern word processors do not render a space between words using the space character in a font. If you want to output a space in the bar code then try using the underscore character (_) which is usually mapped to the same sequence as a space in a Code 39 font.
Pitfall 4: Fused bars
So you’ve avoided Pitfalls 1 to 3 but still can’t get it to read. Take a close look at your bar code – blow it up on the screen so its nice and big. Count the number of bars that have good clear spaces between them. Is the number divisible by 5? If not then somewhere in the printing or scanning process you’ve tried to fit too many bars into too little space and one or more of the spaces between the bars have been lost. This might not sound like a big deal but it’s enough to render a bar code useless. The solution is normally to print the bar code larger or scan at a higher resolution. Either way, until you get the correct number of bars clearly visible your bar code won’t work.
Pitfall 5: Fuzzy bars
What’s this? It’s connected to Pitfall 4 in that it’s the result of too much data in too little space but the image is color rather than black and white. In a color image where a bar code has been packed too tight you get vertical bars in various shades of grey rather than clear black and white. Again, the solution is to print larger or scan at a higher resolution.