This website uses Google cookies to provide its services and analyze your traffic. Your IP address and user-agent are shared with Google, along with performance and security metrics, to ensure quality of service, generate usage statistics and detect and address abuses.More information

Ver sitio en español Go to homepage Contact me
sábado, 9 de julio de 2016

Printing Bar Codes

Sometimes it is necessary to print a bar code on a document or label. There are a lot of formats and encodings, in one or two dimensions, depending on the amount of information to be read by the terminal. In this article I will show three of the most common formats for one-dimensional codes and provide code in CSharp to encode them.

In this link you can download the source code for the BarCodes project, written with Visual Studio 2013. You will also find three fonts of free distribution to print the barcodes.

Code 39

The code 39, or code 3 of 9, system is one of the simplest, and can be written directly into a document with no more than to add the * character at the beginning and end of the string with the code. This is the barcode for the string 812345678901:

Code 39 barcode
Code 39 barcode

This type of code allows use alphanumeric characters and some symbols, it is easy to see which characters are valid simply by typing the string to encode in Word, having selected the bar code font.

With the sample program, you can encode a string to print it using code 39 with the CBEncoder class, by calling the static method CodifyCode39.

Code 128

The code 128 code also supports alphanumeric characters. The advantage over the code 39 is that it is more compact, since the data are encoded and the resulting string is shorter than the input. In addition, a checksum of the data is performed, which prevents incorrect readings. It is more convenient when the text string to encode is long, because the code 39 may generate too long barcodes. This is the result for the string in the previous example:

Code 128 barcode
Code 128 barcode

To encode a string, use the CodifyCode128 function, in the CBEncoder class.

EAN 13

The EAN 13 code is one of the best known. You can see it in almost all commercial products. It is a code that only allows alphanumeric characters. The string must be exactly 12 characters, but can be padded with 0 at the beginning if the code has fewer numbers. Another digit is added, calculated by a checksum, which prevents read errors. This is the aspect with the code that we are using as an example:

EAN 13 barcode
EAN 13 barcode

To encode a string to use this code, call the CodifyEAN13 function of the CBEncoder class.

Share this article: Share in Twitter Share in Facebook Share in Google Plus Share in LinkedIn
Comments (0):
* (Your comment will be published after revision)





Change the CAPTCHA codeSpeak the CAPTCHA code