Show / Hide Table of Contents

Print Jobs

PrintJob, WindowsPrintJob, UnixPrintJob & WebPrintJob

Note

For sample code about using PrintJob, WindowsPrintJob, UnixPrintJob and WebPrintJob classes, please refer to ThermalLabel sample projects

PrintJob

The PrintJob is the object that specifies information about how the ThermalLabel object is generated in raw printer commands, including settings like label orientation and number of copies. It is also used for exporting or saving a ThermalLabel object to raster image formats or Adobe PDF documents which is very useful when you are in development/test phase or have no access to a physical thermal printer.

WindowsPrintJob

The WindowsPrintJob (which is found in the Neodynamic.SDK.ThermalLabel.WindowsPrinting.dll) is the object that specifies information about how the ThermalLabel object is printed, including the printer device settings and communication, label orientation, number of copies, etc. in a Windows client app project.

The WindowsPrintJob also supports BiDirectional Communication i.e. you can send and receive commands to/from the target printer. The following is a sample code about DIBI Comm

UnixPrintJob

The UnixPrintJob (which is found in the Neodynamic.SDK.ThermalLabel.UnixPrinting.dll) is the object that specifies information about how the ThermalLabel object is printed, including the printer device settings and communication, label orientation, number of copies, etc. in a Unix client app project.

WebPrintJob

The WebPrintJob (which is found in the Neodynamic.SDK.ThermalLabel.WebPrinting.dll) is the object that specifies information about how the ThermalLabel object is printed, including the printer device settings and communication, label orientation, number of copies, etc. in an ASP.NET project.

Printer Utilities

ThermalLabel SDK does not only provide thermal label designing and printing but a set of commands for Zebra and Honeywell/Intermec Thermal Printers administration too. ThermalLabel SDK features the PrintUtils object which is used for printing jobs that are not directly related to label printing like printer's memory devices administration. Please refer to PrintUtils class reference for more details. PrinUtils class is available in the Neodynamic.SDK.ThermalLabel.WindowsPrinting.dll and Neodynamic.SDK.ThermalLabel.UnixPrinting.dll assemblies.

Thermal Printer Communication

Thermal Printers can be connected by Serial Port (RS-232), Parallel Port (Centronics), USB and IP Ethernet network depending on the printer model. Printer communication with ThermalLabel SDK is handled by using PrinterCommunication class. However, that class is not directly used in .NET code but through a WindowsPrintJob or UnixPrintJob object or the PrintUtils class which are found in the Neodynamic.SDK.ThermalLabel.WindowsPrinting.dll and Neodynamic.SDK.ThermalLabel.UnixPrinting.dll assemblies.

Important

The Serial Port (RS-232) and Parallel Port (Centronics) communications are not available under Unix (macOS / Linux)

Note

The snipped codes below use WindowsPrintJob but the same applies for UnixPrintJob.

USB

If your printer is connected by USB, then you will have to install/configure a Windows Driver for the printer which can be the Zebra Universal Driver (ZUD) or the Windows built-in "Microsoft Generic Text Only" printer driver before trying to use it with ThermalLabel SDK. The following code is about how to configure printer communication for a printer connected by USB through a WindowsPrintJob object:

Note

These same settings are valid for the PrinterDriver option.

VB

'Create a WindowsPrintJob object
Dim pj As New WindowsPrintJob()
pj.PrinterSettings = New PrinterSettings()
'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"

CS

//Create a WindowsPrintJob object
WindowsPrintJob pj = new WindowsPrintJob();
pj.PrinterSettings = new PrinterSettings();
//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";

Parallel Port (Centronics)

If your printer is connected by Parallel Port (Centronic), then you just need to know the parallel port name to specify it in the PrinterCommunication object. The following code is about how to configure printer communication for a printer connected by LPT1 Parallel Port through a WindowsPrintJob object:

VB

'Create a WindowsPrintJob object
Dim pj As New WindowsPrintJob()
pj.PrinterSettings = New PrinterSettings()
'Thermal Printer is connected through Parallel Port
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Parallel
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer parallel port name
pj.PrinterSettings.ParallelPortName= "LPT1"

CS

//Create a WindowsPrintJob object
WindowsPrintJob pj = new WindowsPrintJob();
pj.PrinterSettings = new PrinterSettings();
//Thermal Printer is connected through Parallel Port
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Parallel;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer parallel port name 
pj.PrinterSettings.ParallelPortName= "LPT1";

Serial Port (RS-232)

If your printer is connected by Serial Port (RS-232), then you need to know the Thermal Printer serial port settings to specify it in the PrinterCommunication object. Please refer to your Printer User Manual and look for the Serial Communication parameters. The following code is about how to configure printer communication for a Zebra printer connected by COM1 Serial Port through a WindowsPrintJob object:

VB

'Create a WindowsPrintJob object
Dim pj As New WindowsPrintJob()
pj.PrinterSettings = New PrinterSettings()
'Thermal Printer is connected through Serial Port
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Serial
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer serial port settings
pj.PrinterSettings.Communication.SerialPortName = "COM1"
pj.PrinterSettings.Communication.SerialPortBaudRate = 9600
pj.PrinterSettings.Communication.SerialPortDataBits = 8
pj.PrinterSettings.Communication.SerialPortStopBits = SerialPortStopBits.One
pj.PrinterSettings.Communication.SerialPortParity = SerialPortParity.None
pj.PrinterSettings.Communication.SerialPortFlowControl = SerialPortHandshake.XOnXOff

CS

//Create a WindowsPrintJob object
WindowsPrintJob pj = new WindowsPrintJob();
pj.PrinterSettings = new PrinterSettings();
//Thermal Printer is connected through Serial Port
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Serial;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer serial port settings 
pj.PrinterSettings.Communication.SerialPortName = "COM1";
pj.PrinterSettings.Communication.SerialPortBaudRate = 9600;
pj.PrinterSettings.Communication.SerialPortDataBits = 8;
pj.PrinterSettings.Communication.SerialPortStopBits = SerialPortStopBits.One;
pj.PrinterSettings.Communication.SerialPortParity = SerialPortParity.None;
pj.PrinterSettings.Communication.SerialPortFlowControl = SerialPortHandshake.XOnXOff;

IP Ethernet Network

If your printer is connected by an IP Ethernet network, then you just need to know the IP Address as well as the port number for the printer to specify them in the PrinterCommunication object. The following code is about how to configure printer communication for a printer connected by IP Ethernet through a WindowsPrintJob object:

VB

'Create a WindowsPrintJob object
Dim pj As New WindowsPrintJob()
pj.PrinterSettings = New PrinterSettings()
'Thermal Printer is connected through IP network
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Network
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer network info
pj.PrinterSettings.Communication.NetworkIPAddress = System.Net.IPAddress.Parse("127.0.0.1")
pj.PrinterSettings.Communication.NetworkPort = 9100

CS

//Create a WindowsPrintJob object
WindowsPrintJob pj = new WindowsPrintJob();
pj.PrinterSettings = new PrinterSettings();
//Thermal Printer is connected through IP network
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Network;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer network info 
pj.PrinterSettings.Communication.NetworkIPAddress = System.Net.IPAddress.Parse("127.0.0.1");
pj.PrinterSettings.Communication.NetworkPort = 9100;
  • In case you do not know which is the IP Address of the printer but the Host name, then you can use the following code instead:

VB

'Create a WindowsPrintJob object
Dim pj As New WindowsPrintJob()
pj.PrinterSettings = New PrinterSettings()
'Thermal Printer is connected through IP network
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Network
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer network info
pj.PrinterSettings.PrinterName = "PRINTER HOST NAME"
pj.PrinterSettings.Communication.NetworkPort = 9100

CS

//Create a WindowsPrintJob object
WindowsPrintJob pj = new WindowsPrintJob();
pj.PrinterSettings = new PrinterSettings();
//Thermal Printer is connected through IP network
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Network;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer network info 
pj.PrinterSettings.PrinterName = "PRINTER HOST NAME";
pj.PrinterSettings.Communication.NetworkPort = 9100;

WindowsPrintJob BiDirectional Communication Sample

The following is a Console sample application about BIDI Comm. Please read the source code and uncomment/change it based on your needs.

Important

Be sure your Console app references the following assemblies: Neodynamic.SDK.ThermalLabel.dll Neodynamic.SDK.ThermalLabel.WindowsPrinting.NetCore.dll or Neodynamic.SDK.ThermalLabel.WindowsPrinting.dll

VB

vbnet
Imports System
Imports System.Linq
Imports Neodynamic.SDK.Printing

Namespace TLBidiSample
    Class Program
        Shared Sub Main(args As String())
            Console.WriteLine("Starting BIDI Comm...")

            ' The target printer settings for BIDI comm
            Dim ps As New PrinterSettings()

            ' Targeting driver installed printer
            '
            ' ps.Communication.CommunicationType = CommunicationType.PrinterDriver
            ' ps.PrinterName = "ZDesigner GK420t"
            '

            ' Targeting IP Network Printer
            '
            ' ps.Communication.CommunicationType = CommunicationType.Network
            ' ps.Communication.NetworkIPAddress = System.Net.IPAddress.Parse("127.0.0.1")
            ' ps.Communication.NetworkPort = 9100
            '

            ' Targeting USB printer
            '
            ' ps.Communication.CommunicationType = CommunicationType.USB
            ' Try
            '     ps.PrinterName = PrintUtils.GetUsbDevices().First().DevicePath
            ' Catch ex As Exception
            '     Console.Error.WriteLine($"USB Device error: {ex.Message}")
            '     Return
            ' End Try
            '

            ' The WindowsPrintJob obj
            Using wpj As New WindowsPrintJob(ps)

                ' Handle errors
                AddHandler wpj.Error, Sub(sender, e)
                                          Console.Error.WriteLine(e.Exception.Message)
                                      End Sub

                ' Handler received data from target device
                AddHandler wpj.DataRead, Sub(sender, e)
                                             Console.WriteLine($"Received: {e.Data}")
                                         End Sub

                ' Open a BIDI comm
                wpj.OpenBidiComm()

                Dim input As String = ""
                Console.WriteLine("Enter printer commands, or type 'exit' to quit.")

                While True
                    Console.Write("> ")
                    input = Console.ReadLine()

                    If input IsNot Nothing AndAlso (input.ToLower() = "quit" OrElse input.ToLower() = "exit") Then
                        Console.WriteLine("Exit command received. Exiting application.")
                        Exit While
                    End If

                    ' Write (send) data to the target device
                    wpj.Write(input)
                End While

                ' Close BIDI comm
                wpj.CloseBidiComm()

            End Using

        End Sub
    End Class
End Namespace

CS

using System;
using System.Linq;
using Neodynamic.SDK.Printing;

namespace TLBidiSample
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Starting BIDI Comm...");

            // The target printer settings for BIDI comm
            var ps = new PrinterSettings();

            // Targeting driver installed printer
            /*
            ps.Communication.CommunicationType = CommunicationType.PrinterDriver;
            ps.PrinterName = "ZDesigner GK420t";
            */

            // Targeting IP Network Printer
            /*
            ps.Communication.CommunicationType = CommunicationType.Network;
            ps.Communication.NetworkIPAddress = System.Net.IPAddress.Parse("127.0.0.1");
            ps.Communication.NetworkPort = 9100;
            */

            // Targeting USB printer
            /*
            ps.Communication.CommunicationType = CommunicationType.USB;
            try
            {
                ps.PrinterName = PrintUtils.GetUsbDevices().First().DevicePath;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"USB Device error: {ex.Message}");
                return;
            }
            */

            // The WindowsPrintJob obj
            using var wpj = new WindowsPrintJob(ps);

            // Handle errors
            wpj.Error += (sender, e) =>
            {
                Console.Error.WriteLine(e.Exception.Message);
            };

            // Handler received data from target device
            wpj.DataRead += (sender, e) =>
            {
                Console.WriteLine($"Received: {e.Data}");
            };

            // Open a BIDI comm
            wpj.OpenBidiComm();

            string input = "";
            Console.WriteLine("Enter printer commands, or type 'exit' to quit.");

            while (true)
            {
                Console.Write("> ");
                input = Console.ReadLine();

                if (input != null && (input.ToLower() == "quit" || input.ToLower() == "exit"))
                {
                    Console.WriteLine("Exit command received. Exiting application.");
                    break;
                }

                // Write (send) data to the target device
                wpj.Write(input);

            }

            // Close BIDI comm
            wpj.CloseBidiComm();

        }
    }
}
Back to top Copyright © 2003- Neodynamic SRL
http://www.neodynamic.com