../
2016-05-31: The /* Programming Comments */ documents have moved, and will no longer be updated or maintained at this location! Please update your bookmarks: http://www.ccoderun.ca/programming/.

Summary

Probably one of the simplest and most common barcode type is called Code39. It is a one-dimensional barcode, and it has a very limited character set, but every barcode reader out there can read Code39. There are fonts available for Code39, but on the project I was working on, I needed to embed some simple barcodes in HTML pages.

How It Works

Every character is composed of 2 wide dark bars, 1 wide light bar, 3 thin dark bars, and 3 thin light bars. In addition, the spacing between each character is typically the width of 1 thin light bar. This makes Code39 a monospaced font, since every character is exactly the same width.

The character set is very small. Zero through nine, A through Z (uppercase), and a small handful of special characters.

Each Code39 barcode starts with a quiet zone, followed by asterix. Then the barcode, terminated with another asterix and another quiet zone.

Examples

For example, to encode the word TESTING, you'd use the following characters:  * T E S T I N G *

Put together as a barcode, the word TESTING encoded as  *TESTING*  looks like this:

 * T E S T I N G *

Character Set

The complete Code39 character set is available from here. From the full set, I extracted some of the more common characters I needed, which are available from here. Here are the common 135x135 characters:

0
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
I
I
J
J
K
K
L
L
M
M
N
N
O
O
P
P
Q
Q
R
R
S
S
T
T
U
U
V
V
W
W
X
X
Y
Y
Z
Z
*
(asterix)
-
(dash)
.
(period)

(space)
quiet
quiet

The images are 135 pixels wide and high, which makes it easy to resize to 9, 15, 27, or 45 pixels.

The full-sized 135 pixel images look like this:

Last modified: 2015-06-09
Stéphane Charette, stephanecharette@gmail.com
../