See Also
Features
Buy Now
Online Help
Demo
Licensing

Back

How to print a set of barcode labels in batch using counter 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)
Counters allow you to index data items by a selected increment or decrement value, making the data items increase or decrease by a specified value each time a label is printed. Counters can be used with TextItem as well as BarcodeItem objects. The first integer number found in the Text property (for TextItem objects) or Code property (for BarcodeItem objects) when scanning from right to left starts the indexing portion of the data item. If the alphanumeric field to be indexed ends with an alpha character, the data is scanned, character by character, from right to left until a numeric character is encountered.

In this guide you will learn how to print 10 barcode labels for values ranging from "ABC01" to "ABC10" leveraging counters feature with Zebra ZPL or 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 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, 6, 0)
    
    'Define a TextItem object
    Dim txt As New TextItem(0.5, 0.5, "Decreasing 50")
    'Set font...
    txt.Font.CharHeight = 14
    'set Counter...
    txt.CounterStep = -1
    
    'Define a BarcodeItem object
    Dim bc As New BarcodeItem(0.5, 1.5, BarcodeSymbology.Code128, "ABC01")
    'Set bars' width and height...
    bc.BarWidth = 0.04
    bc.BarHeight = 2
    'set Counter...
    bc.CounterStep = 1
    bc.CounterUseLeadingZeros = True
    
    'Add items to ThermalLabel object...
    tLabel.Items.Add(txt)
    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  GK420t"
    'Set Copies to 10!!!
    pj.Copies = 10
    '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, 6, 0);
    
    //Define a TextItem object
    TextItem txt = new TextItem(0.5, 0.5, "Decreasing 50");
    //Set font...
    txt.Font.CharHeight = 14;
    //set Counter...
    txt.CounterStep = -1;
    
    //Define a BarcodeItem object
    BarcodeItem bc = new BarcodeItem(0.5, 1.5, BarcodeSymbology.Code128, "ABC01");
    //Set bars' width and height...
    bc.BarWidth = 0.04;
    bc.BarHeight = 1;
    //set Counter...
    bc.CounterStep = 1;
    bc.CounterUseLeadingZeros = true;
    
    //Add items to ThermalLabel object...
    tLabel.Items.Add(txt);
    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  GK420t";
    //Set Copies to 10!!!
    pj.Copies = 10;
    //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, 6, 0)
    
    'Define a TextItem object
    Dim txt As New TextItem(0.5, 0.5, "Decreasing 50")
    'Set font...
    txt.Font.Name = "2"
    txt.Font.CharHeight = 14
    txt.Font.CharWidth = 8
    'set Counter...
    txt.CounterStep = -1
    
    'Define a BarcodeItem object
    Dim bc As New BarcodeItem(0.5, 1.5, BarcodeSymbology.Code128, "ABC01")
    'Set bars' width and height...
    bc.BarWidth = 0.04
    bc.BarHeight = 2
    'set Counter...
    bc.CounterStep = 1
    bc.CounterUseLeadingZeros = True
    
    'Add items to ThermalLabel object...
    tLabel.Items.Add(txt)
    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"
    'Set Copies to 10!!!
    pj.Copies = 10
    '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, 6, 0);
    
    //Define a TextItem object
    TextItem txt = new TextItem(0.5, 0.5, "Decreasing 50");
    //Set font...
    txt.Font.Name = "2";
    txt.Font.CharHeight = 14;
    txt.Font.CharWidth = 8;
    //set Counter...
    txt.CounterStep = -1;
    
    //Define a BarcodeItem object
    BarcodeItem bc = new BarcodeItem(0.5, 1.5, BarcodeSymbology.Code128, "ABC01");
    //Set bars' width and height...
    bc.BarWidth = 0.04;
    bc.BarHeight = 1;
    //set Counter...
    bc.CounterStep = 1;
    bc.CounterUseLeadingZeros = true;
    
    //Add items to ThermalLabel object...
    tLabel.Items.Add(txt);
    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";
    //Set Copies to 10!!!
    pj.Copies = 10;
    //Print ThermalLabel object...
    pj.Print(tLabel);
    
  • Run the sample Windows Forms application and test it.
If you need more information or assistance, please contact our .
 Copyright © 2003 - 2010 Neodynamic S.R.L. All rights reserved.