CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2008
    Posts
    136

    Thumbs up How to data binding ADO.NET DataSet XML to print barcode labels with Zebra ZPL-EPL...

    How to data binding ADO.NET DataSet XML to print barcode labels 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)

    ThermalLabel SDK supports .NET Data Binding scenarios allowing you to print thermal labels bound to a data source such as custom .NET objects, XML files, Databases, ADO.NET, etc.

    In this guide you will learn how to perform data binding with XML files to print barcode labels with Zebra ZPL printers by using ThermalLabel SDK for .NET

    The following sample features a XML file containing books info. An ADO.NET DataSet object wrapping the books info from the XML source and a ThermalLabel objects will be used to perform data binding scenario printing a set of thermal labels for each book as shown in the following figure.

    http://www.neodynamic.com/demo-faq/t...SDK-fo-NET.jpg

    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.
    - Create a XML File in C:\temp\books.xml with the following content:
    <Books xmlns="">
    <Book ISBN="0-7356-0562-9" Title="XML in Action" />
    <Book ISBN="0-7356-1377-X" Title="Introducing Microsoft .NET" />
    <Book ISBN="0-7356-1288-9" Title="Inside C#" />
    <Book ISBN="0-7356-1370-2" Title="Programming Microsoft Windows With C#" />
    <Book ISBN="0-7356-1448-2" Title="Microsoft C# Language Specifications" />
    </Books>

    - 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)

    'TextItem for ISBN Text...
    Dim txt1 As New TextItem(0.75, 0.5, "")
    'set font...
    txt1.Font.Name = "0"
    txt1.Font.CharHeight = 12
    'set text...
    txt1.Text = "ISBN:"

    'TextItem for ISBN data field...
    Dim txt2 As New TextItem(2, 0.5, "")
    'set font...
    txt2.Font.Name = "0"
    txt2.Font.CharHeight = 10
    'set Data Source field...
    txt2.DataField = "ISBN"

    'BarcodeItem for encoding ISBN data field...
    Dim bc As New BarcodeItem(1.25, 1.3, BarcodeSymbology.Isbn, "")
    'Set Data Source field...
    bc.DataField = "ISBN"
    'Set barcode dimensions
    bc.BarHeight = 2
    bc.BarWidth = 0.04

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

    'Create data source...
    Dim books As New DataSet()
    books.ReadXml("c:\temp\books.xml")

    'set data source...
    tLabel.DataSource = books.Tables("Book")

    '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, 6, 0);

    //TextItem for ISBN Text...
    TextItem txt1 = new TextItem(0.75, 0.5, "");
    //set font...
    txt1.Font.Name = "0";
    txt1.Font.CharHeight = 12;
    //set text...
    txt1.Text = "ISBN:";

    //TextItem for ISBN data field...
    TextItem txt2 = new TextItem(2, 0.5, "");
    //set font...
    txt2.Font.Name = "0";
    txt2.Font.CharHeight = 10;
    //set Data Source field...
    txt2.DataField = "ISBN";

    //BarcodeItem for encoding ISBN data field...
    BarcodeItem bc = new BarcodeItem(1.25, 1.3, BarcodeSymbology.Isbn, "");
    //Set Data Source field...
    bc.DataField = "ISBN";
    //Set barcode dimensions
    bc.BarHeight = 2;
    bc.BarWidth = 0.04;

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

    //Create data source...
    DataSet books = new DataSet();
    books.ReadXml(@"c:\temp\books.xml");

    //set data source...
    tLabel.DataSource = books.Tables["Book"];

    //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, 6, 0)

    'TextItem for ISBN Text...
    Dim txt1 As New TextItem(0.75, 0.5, "")
    'set font...
    txt1.Font.Name = "1"
    txt1.Font.CharHeight = 14
    txt1.Font.CharWidth = 8
    'set text...
    txt1.Text = "ISBN:"

    'TextItem for ISBN data field...
    Dim txt2 As New TextItem(2, 0.6, "")
    'set font...
    txt2.Font.Name = "1"
    txt2.Font.CharHeight = 10
    txt2.Font.CharWidth = 6
    'set Data Source field...
    txt2.DataField = "ISBN"

    'BarcodeItem for encoding ISBN data field...
    Dim bc As New BarcodeItem(1.25, 1.3, BarcodeSymbology.Isbn, "")
    'Set Data Source field...
    bc.DataField = "ISBN"
    'Set barcode dimensions
    bc.BarHeight = 2
    bc.BarWidth = 0.04

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

    'Create data source...
    Dim books As New DataSet()
    books.ReadXml("c:\temp\books.xml")

    'set data source...
    tLabel.DataSource = books.Tables("Book")

    '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, 6, 0);

    //TextItem for ISBN Text...
    TextItem txt1 = new TextItem(0.75, 0.5, "");
    //set font...
    txt1.Font.Name = "1";
    txt1.Font.CharHeight = 14;
    txt1.Font.CharWidth = 8;
    //set text...
    txt1.Text = "ISBN:";

    //TextItem for ISBN data field...
    TextItem txt2 = new TextItem(2, 0.6, "");
    //set font...
    txt2.Font.Name = "1";
    txt2.Font.CharHeight = 10;
    txt2.Font.CharWidth = 6;
    //set Data Source field...
    txt2.DataField = "ISBN";

    //BarcodeItem for encoding ISBN data field...
    BarcodeItem bc = new BarcodeItem(1.25, 1.3, BarcodeSymbology.Isbn, "");
    //Set Data Source field...
    bc.DataField = "ISBN";
    //Set barcode dimensions
    bc.BarHeight = 2;
    bc.BarWidth = 0.04;

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

    //Create data source...
    DataSet books = new DataSet();
    books.ReadXml(@"c:\temp\books.xml");

    //set data source...
    tLabel.DataSource = books.Tables["Book"];

    //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.


    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

  2. #2
    Join Date
    Mar 2010
    Posts
    1

    Re: How to data binding ADO.NET DataSet XML to print barcode labels with Zebra ZPL-EP

    Hi,
    after reading your thread i checked out the neodynamic website
    because i am currently looking for something very similar.
    we are working on a compact framework solution for mobile assets.
    therefore we would like to print labels with barcodes on-site.

    i am not quite sure which of the neodynamics sdks we would have to get,
    in order to achieve our goal. we have worked with zebra printers.
    network connectivity with the printer (either mobile or desktop printer) with the windows mobile device isnt a problem but how do we communicate with the printer from the mobile device?
    as you probably know there are no printer drivers for windows mobile, at least not provided by microsoft or zebra.

    is the thermal sdk enough? what about the compact framework sdk.

    i actually like the following idea best:
    1. design a label template on a desktop computer
    2. upload the label to the printer (e.g. a GK420t or P4T)
    3. connect the mobile device to the printer (wireless, serial or usb)
    4. send xml data to the printer through the CF application
    5. get the label printed

    thanks for any ideas on this.

    MP

  3. #3
    Join Date
    Feb 2011
    Posts
    1

    Re: How to data binding ADO.NET DataSet XML to print barcode labels with Zebra ZPL-EP

    I think this will help you:
    <a href="http://www.liquid-technologies.com/Tutorials/XMLDataBinding/Xml-Data-Binding-Tutorial.aspx">http://www.liquid-technologies.com/Tutorials/XMLDataBinding/Xml-Data-Binding-Tutorial.aspx</a>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured