Introduction

EAN-13 is a Standard - Barcode - format. This code is used to scan articles in stores and other places. For a project I'm working on, I need to print EAN - Codes on a Laser printer and display them on the screen for the user. The printing task is quite easy since most printers support EAN - Codes, if you pass them an escape sequence. The trouble is, that you can pass the escape sequences only if you open the port manually and print the whole page with print-commands, which means, you can not use the System.Drawing.Printing objects. So, if you want to print EAN - Codes and use the Print objects of .NET, you need to draw the EAN - Codes yourself.

The EAN - Format

To draw an EAN - 13 formatted Barcode you need three tables which tell you how to format each digit. The first and the second are used for the digits 1 - 7 and the third table is used for the digits 8 - 13. Each digit is 12 bits long; if you count the 2 bits separators they are 14 bits long.

These are the three tables with the digits and their decimal value in the barcode:

Digit

Table 1

Table 2

Table 3

0

243

3135

4035

1

963

3855

3855

2

783

975

3900

3

4083

3075

3075

4

3087

1011

3324

5

3843

4035

3135

6

3327

51

3264

7

4047

771

3084

8

3903

195

3120

9

207

831

4044

Now the question is: Why do we use two tables for the first 7 digits? Answer: Because the first digit is not really printed, if you look at the code you only see the digits 2-13. First digit is decoded by the variations of the usage for the drawing of digits 2-7.

These are the combinations we use to decode the first digit:

Value: Digit1

Tab for Digit2

Digit3

Digit4

Digit5

Digit6

Digit7

0

1

1

1

1

1

1

1

1

1

2

1

2

2

2

1

1

2

2

1

2

3

1

1

2

2

2

1

4

1

2

1

1

2

2

5

1

2

2

1

1

2

6

1

2

2

2

1

1

7

1

2

1

2

1

2

8

1

2

1

2

2

1

9

1

2

2

1

2

1

Now, the last important thing is the 13th digit. You can't choose it freely. It's a checksum. It's calculated in the following way:

Go through digits 1-12, if the digit is even add the value, if not add the value * 3.