How to print Code 39 barcode encoding full ASCII text with Zebra ZPL-EPL printers and VB.NET or C# by using ThermalLabel SDK for .NET
Prerequisites
- Neodynamic ThermalLabel SDK 2.0 for .NET
- Microsoft .NET Framework 2.0 (or greater)
- Microsoft Visual Studio 2005 / 2008
- Microsoft Visual Studio 2005 / 2008 Express Editions (VB, C#, J#, and C++)
- Any Zebra Thermal Printer supporting ZPL (Zebra Programming Language) or EPL (Eltron Programming Language)

All Zebra (ZPL-based and EPL-based) thermal barcode printers provide built-in support for printing Code 39 barcodes as well as other barcode standards.

Code 39 barcode is suitable for encoding general purpose alphanumeric data. By default, Code 39 can encode uppercase letters (A through Z), digits (0 through 9) and a handful of special characters like the *, -, $, %, (Space), ., /, and +. However, it is possible to encode all 128 ASCII characters as well by using the "extended version" of Code 39. It is important to note that the * (asterisk) found on Code 39 barcodes is not a true encodable character, but is the start and stop "symbol". In this guide you will learn how to print full ASCII Code 39 barcodes with Zebra ZPL-EPL printers by using ThermalLabel SDK for .NET

IMPORTANT: To test the sample code you must have installed a Zebra ZPL-based or EPL-based thermal printer.

Follow these steps:
- Download and install latest version of Neodynamic ThermalLabel SDK for .NET
- Open Visual Studio 2005 /2008 and create a Windows Forms application.
- Add a reference to Neodynamic.SDK.ThermalLabel.dll assembly.
- Add a button control onto the form and paste the following code in the click event handler of the button:

IMPORTANT NOTICE
Although ThermalLabel SDK supports both ZPL and EPL printers, a label design you write using .NET code like C# or VB.NET will not produce the same output printing under ZPL and EPL printers. If you need to support both printer languages in your project then you will have to design two different labels targeting each printer language separately.

For ZPL-based Printers
Visual Basic .NET
'Define a ThermalLabel object and set unit to cm and label size
Dim tLabel As New ThermalLabel(UnitType.Cm, 10, 0)

'Define a BarcodeItem object
Dim bc As New BarcodeItem(1, 1, BarcodeSymbology.Code39, "lower123")
'Set bars' width and height...
bc.BarWidth = 0.04
bc.BarHeight = 2
'Disable checksum...
bc.AddChecksum = false

'Add items to ThermalLabel object...
tLabel.Items.Add(bc)

'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra TLP2844-Z"
'Print ThermalLabel object...
pj.Print(tLabel)

Visual C# .NET
//Define a ThermalLabel object and set unit to cm and label size
ThermalLabel tLabel = new ThermalLabel(UnitType.Cm, 10, 0);

//Define a BarcodeItem object
BarcodeItem bc = new BarcodeItem(1, 1, BarcodeSymbology.Code39, "lower123");
//Set bars' width and height...
bc.BarWidth = 0.04;
bc.BarHeight = 2;
//Disable checksum...
bc.AddChecksum = false;

//Add items to ThermalLabel object...
tLabel.Items.Add(bc);

//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra TLP2844-Z";
//Print ThermalLabel object...
pj.Print(tLabel);


For EPL-based Printers
Visual Basic .NET
'Define a ThermalLabel object and set unit to cm and label size
Dim tLabel As New ThermalLabel(UnitType.Cm, 10, 0)

'Define a BarcodeItem object
Dim bc As New BarcodeItem(1, 1, BarcodeSymbology.Code39, "lower123")
'Set bars' width and height...
bc.BarWidth = 0.04
bc.BarHeight = 2
'Disable checksum...
bc.AddChecksum = false

'Add items to ThermalLabel object...
tLabel.Items.Add(bc)

'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.EPL
'Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra GK420t"
'Print ThermalLabel object...
pj.Print(tLabel)

Visual C# .NET
//Define a ThermalLabel object and set unit to cm and label size
ThermalLabel tLabel = new ThermalLabel(UnitType.Cm, 10, 0);

//Define a BarcodeItem object
BarcodeItem bc = new BarcodeItem(1, 1, BarcodeSymbology.Code39, "lower123");
//Set bars' width and height...
bc.BarWidth = 0.04;
bc.BarHeight = 2;
//Disable checksum...
bc.AddChecksum = false;

//Add items to ThermalLabel object...
tLabel.Items.Add(bc);

//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.EPL;
//Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra GK420t";
//Print ThermalLabel object...
pj.Print(tLabel);

- Run the sample Windows Forms application and test it. The Thermal Printer should print a label with a Code 39 barcode.

If the Human Readable Text is not correctly printed in ZPL-based printers...

Sadly, some Zebra ZPL Firmware versions do not support printing full ASCII human readable text when using Code 39 i.e. for example, based on the code above your Zebra printer will print +L+O+W+E+R123 instead of lower123 in the human readable text. To solve this issue you will have to not display human readable text on the barcode (by using DisplayCode property of BarcodeItem object) and replace it by using a TextItem. In addition, for centering human readable text below the barcode bars, you could use a TableShapeItem. The following code uses a table with 1 column and 2 rows trying to work-around the firmware issue.

Visual Basic .NET
'Define a ThermalLabel object and set unit to cm and label size
Dim tLabel As New ThermalLabel(UnitType.Cm, 10, 0)

'Define a TableShapeItem object
Dim table As New TableShapeItem(1, 1, 8, 3, 1, 2)
'Set row's height...
table.Rows(0).Height = 2
table.Rows(1).Height = 1
'hide cell borders...
table.StrokeThickness = 0
'set cell spacing...
table.CellSpacing = 0.1
'set barcode in cell 0,0
table.Cells(0, 0).Content = CellContent.Barcode
table.Cells(0, 0).ContentBarcode.Symbology = BarcodeSymbology.Code39
table.Cells(0, 0).ContentBarcode.Code = "lower123"
table.Cells(0, 0).ContentBarcode.BarWidth = 0.04
table.Cells(0, 0).ContentBarcode.BarHeight = 2
table.Cells(0, 0).ContentBarcode.AddChecksum = false
table.Cells(0, 0).ContentBarcode.DisplayCode = false
'set barcode in cell 1,0
table.Cells(1, 0).Content = CellContent.Text
table.Cells(1, 0).ContentText.Text = "lower123"
table.Cells(1, 0).ContentText.Font.CharHeight = 12
table.Cells(1, 0).ContentAlignment = CellContentAlignment.Center

'Add items to ThermalLabel object...
tLabel.Items.Add(table)

'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra TLP2844-Z"
'Print ThermalLabel object...
pj.Print(tLabel)

Visual C# .NET
//Define a ThermalLabel object and set unit to cm and label size
ThermalLabel tLabel = new ThermalLabel(UnitType.Cm, 10, 0);

//Define a TableShapeItem object
TableShapeItem table = new TableShapeItem(1, 1, 8, 3, 1, 2);
//Set row's height...
table.Rows[0].Height = 2;
table.Rows[1].Height = 1;
//hide cell borders...
table.StrokeThickness = 0;
//set cell spacing...
table.CellSpacing = 0.1;
//set barcode in cell 0,0
table.Cells[0, 0].Content = CellContent.Barcode;
table.Cells[0, 0].ContentBarcode.Symbology = BarcodeSymbology.Code39;
table.Cells[0, 0].ContentBarcode.Code = "lower123";
table.Cells[0, 0].ContentBarcode.BarWidth = 0.04;
table.Cells[0, 0].ContentBarcode.BarHeight = 2;
table.Cells[0, 0].ContentBarcode.AddChecksum = false;
table.Cells[0, 0].ContentBarcode.DisplayCode = false;
//set barcode in cell 1,0
table.Cells[1, 0].Content = CellContent.Text;
table.Cells[1, 0].ContentText.Text = "lower123";
table.Cells[1, 0].ContentText.Font.CharHeight = 12;
table.Cells[1, 0].ContentAlignment = CellContentAlignment.Center;

//Add items to ThermalLabel object...
tLabel.Items.Add(table);

//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra TLP2844-Z";
//Print ThermalLabel object...
pj.Print(tLabel);


Links:
This Demo
More Demos
Download ThermalLabel SDK for .NET
More Information about Neodynamic ThermalLabel SDK for .NET


Neodynamic
.NET Components & Controls
http://www.neodynamic.com