Barcodes

Code 3 of 9 Barcodes

code39.png

I acquired the Code 3 of 9 algorithm from Ed Rickman at the Research Tri­angle Insti­tute in 1991 while I was work­ing for Com­puter Sciences Corpo­ra­tion under con­tract to the U.S. EPA on a proj­ect to re­design the data­base for the Radon Meas­ure­ment Pro­fi­ciency (RMP) Pro­gram. CSC and EPA used it to bar­code mail­ing labels for par­tici­pants in the program.

The source code was developed as C++, but it is really just plain old C. There’s nothing object-​oriented about it.

Feel free to take the C/C++ code and modify it to suit your needs. That’s what I did with the Pascal code that Ed gave me.

Note: You can print bar­codes, includ­ing Code 3 of 9 bar­codes, just by acquir­ing the right fonts for your com­puter (e.g., openfontlibrary.org). Don’t waste time pro­gram­ming your own bar­codes if a new font will meet your needs. I pro­duced the bar­code shown above using a free True­Type font made by IDAuto­ma­tion and down­loaded from open­font­library.org. I made it a PNG image rather than use the font it­self here and worry about licens­ing restric­tions and browser com­pat­ibility issues.
File Description
barcode.zip Zipped file con­tain­ing the source code
code39.h Header file for the Code 3 of 9 functions
text39.h Header file for digi­tized text functions
hpbar.h Header file for print­ing bar­codes on a PCL® printer
code39.cpp C++ source for encod­ing text strings as Code 3 of 9 barcodes
text39.cpp C++ source code for encod­ing text strings in a bit-​mapped font, which can be com­bined with a Code 3 of 9 barcode
hpbar.cpp C++ source code for dis­play­ing bar­codes (with text) on a PCL printer

By the way, the original postal bar­codes (POST­NET) are even simpler than Code39. (There are only 10 char­acters.) If you like math­ematical and logi­cal puzzles, and you don’t already know the encod­ing algo­rithm for POST­NET, try figur­ing it out just by look­ing at sev­eral examples (if you can still find them).