Show / Hide Table of Contents

Getting Started

ZPLPrinter Emulator SDK works like a Virtual ZPL Printer device. You setup the virtual printer with basic settings like the DPI resolution and default Label Size to finally pass to it the ZPL commands to be processed.

First sample code - Convert ZPL to PDF

This first sample code creates an instance of ZPLPrinter class, then set the virtual printer properties and pass to it the ZPL commands to be processed. Finally, the output rendering is saved to a PDF file on disk.

C# - First sample code - Convert ZPL to PDF

using Neodynamic.SDK.ZPLPrinter;

//...

try
{

    //The ZPL commands to be rendered...
    string zplCommands = "^XA^FO20,30^GB750,1100,4^FS^FO20,30^GB750,200,4^FS^FO20,30^GB750,400,4^FS^FO20,30^GB750,700,4^FS^FO20,226^GB325,204,4^FS^FO30,40^ADN,36,20^FDShip to:^FS^FO30,260^ADN,18,10^FDPart number #^FS^FO360,260^ADN,18,10^FDDescription:^FS^FO30,750^ADN,36,20^FDFrom:^FS^FO150,125^ADN,36,20^FDAcme Printing^FS^FO60,330^ADN,36,20^FD14042^FS^FO400,330^ADN,36,20^FDScrew^FS^FO70,480^BY4^B3N,,200^FD12345678^FS^FO150,800^ADN,36,20^FDMacks Fabricating^FS^XZ";

    //Create an instance of ZPLPrinter class
    using (var myZPLPrinter = new ZPLPrinter("LICENSE OWNER", "LICENSE KEY"))
    {
        //Set printer DPI
        //The DPI value to be set must match the value for which 
        //the ZPL commands to be processed were created!!!
        myZPLPrinter.Dpi = 203;
        //Apply antialiasing?
        myZPLPrinter.AntiAlias = true;
        //set label size e.g. 4in x 6in
        myZPLPrinter.LabelWidth = 4 * myZPLPrinter.Dpi;
        myZPLPrinter.LabelHeight = 6 * myZPLPrinter.Dpi;
        //Set image or doc format for output rendering 
        myZPLPrinter.RenderOutputFormat = RenderOutputFormat.PDF;
        //Set ZPL commands to be processed...
        var buffer = myZPLPrinter.ProcessCommands(zplCommands, enc);

        // the buffer variable contains the binary output of the ZPL rendering result
        // The format of this buffer depends on the RenderOutputFormat property setting
        if (buffer != null && buffer.Count > 0)
        {
            //Save output rendering to PDF
            System.IO.File.WriteAllBytes(@"c:\temp\sample-zpl-label.pdf", buffer[0]);
        }
    }
}
catch (Exception ex)
{
    throw ex;
}

VB - First sample code - Convert ZPL to PDF


Imports Neodynamic.SDK.ZPLPrinter
'...
Try 
    'The ZPL commands to be rendered...
    Dim zplCommands As String = "^XA^FO20,30^GB750,1100,4^FS^FO20,30^GB750,200,4^FS^FO20,30^GB750,400,4^FS^FO20,30^GB750,700,4^FS^FO20"& _ 
    ",226^GB325,204,4^FS^FO30,40^ADN,36,20^FDShip to:^FS^FO30,260^ADN,18,10^FDPart number #^FS^FO360,260^"& _ 
    "ADN,18,10^FDDescription:^FS^FO30,750^ADN,36,20^FDFrom:^FS^FO150,125^ADN,36,20^FDAcme Printing^FS^FO6"& _ 
    "0,330^ADN,36,20^FD14042^FS^FO400,330^ADN,36,20^FDScrew^FS^FO70,480^BY4^B3N,,200^FD12345678^FS^FO150,"& _ 
    "800^ADN,36,20^FDMacks Fabricating^FS^XZ"

    'Create an instance of ZPLPrinter class
    Using myZPLPrinter = New ZPLPrinter("LICENSE OWNER", "LICENSE KEY")
        'Set printer DPI
        'The DPI value to be set must match the value for which 
        'the ZPL commands to be processed were created!!!
        myZPLPrinter.Dpi = 203
        'Apply antialiasing?
        myZPLPrinter.AntiAlias = true
        'set label size e.g. 4in x 6in
        myZPLPrinter.LabelWidth = (4 * myZPLPrinter.Dpi)
        myZPLPrinter.LabelHeight = (6 * myZPLPrinter.Dpi)
        'Set image or doc format for output rendering 
        myZPLPrinter.RenderOutputFormat = RenderOutputFormat.PDF
        'Set ZPL commands to be processed...
        Dim buffer = myZPLPrinter.ProcessCommands(zplCommands, enc)
        ' the buffer variable contains the binary output of the ZPL rendering result
        ' The format of this buffer depends on the RenderOutputFormat property setting
        If ((Not (buffer) Is Nothing)  _
                    AndAlso (buffer.Count > 0)) Then
            'Save output rendering to PDF
            System.IO.File.WriteAllBytes("c:\temp\sample-zpl-label.pdf", buffer(0))
        End If
    End Using

Catch ex As Exception
    Throw ex
End Try

Sample code - Convert ZPL to PNG

This sample code creates an instance of ZPLPrinter class, then set the virtual printer properties and pass to it the ZPL commands to be processed. Finally, the output rendering is saved to a PNG file on disk.

C# - Sample code - Convert ZPL to PNG

using Neodynamic.SDK.ZPLPrinter;

//...

try
{

    //The ZPL commands to be rendered...
    string zplCommands = "^XA^FO20,30^GB750,1100,4^FS^FO20,30^GB750,200,4^FS^FO20,30^GB750,400,4^FS^FO20,30^GB750,700,4^FS^FO20,226^GB325,204,4^FS^FO30,40^ADN,36,20^FDShip to:^FS^FO30,260^ADN,18,10^FDPart number #^FS^FO360,260^ADN,18,10^FDDescription:^FS^FO30,750^ADN,36,20^FDFrom:^FS^FO150,125^ADN,36,20^FDAcme Printing^FS^FO60,330^ADN,36,20^FD14042^FS^FO400,330^ADN,36,20^FDScrew^FS^FO70,480^BY4^B3N,,200^FD12345678^FS^FO150,800^ADN,36,20^FDMacks Fabricating^FS^XZ";

    //Create an instance of ZPLPrinter class
    using (var myZPLPrinter = new ZPLPrinter("LICENSE OWNER", "LICENSE KEY"))
    {
        //Set printer DPI
        //The DPI value to be set must match the value for which 
        //the ZPL commands to be processed were created!!!
        myZPLPrinter.Dpi = 203;
        //Apply antialiasing?
        myZPLPrinter.AntiAlias = true;
        //set label size e.g. 4in x 6in
        myZPLPrinter.LabelWidth = 4 * myZPLPrinter.Dpi;
        myZPLPrinter.LabelHeight = 6 * myZPLPrinter.Dpi;
        //Set image or doc format for output rendering 
        myZPLPrinter.RenderOutputFormat = RenderOutputFormat.PNG;
        //Set ZPL commands to be processed...
        var buffer = myZPLPrinter.ProcessCommands(zplCommands, enc);

        // the buffer variable contains the binary output of the ZPL rendering result
        // The format of this buffer depends on the RenderOutputFormat property setting
        if (buffer != null && buffer.Count > 0)
        {
            //Save output rendering to PDF
            System.IO.File.WriteAllBytes(@"c:\temp\sample-zpl-label.png", buffer[0]);
        }
    }
}
catch (Exception ex)
{
    throw ex;
}

VB - Sample code - Convert ZPL to PDF


Imports Neodynamic.SDK.ZPLPrinter
'...
Try 
    'The ZPL commands to be rendered...
    Dim zplCommands As String = "^XA^FO20,30^GB750,1100,4^FS^FO20,30^GB750,200,4^FS^FO20,30^GB750,400,4^FS^FO20,30^GB750,700,4^FS^FO20"& _ 
    ",226^GB325,204,4^FS^FO30,40^ADN,36,20^FDShip to:^FS^FO30,260^ADN,18,10^FDPart number #^FS^FO360,260^"& _ 
    "ADN,18,10^FDDescription:^FS^FO30,750^ADN,36,20^FDFrom:^FS^FO150,125^ADN,36,20^FDAcme Printing^FS^FO6"& _ 
    "0,330^ADN,36,20^FD14042^FS^FO400,330^ADN,36,20^FDScrew^FS^FO70,480^BY4^B3N,,200^FD12345678^FS^FO150,"& _ 
    "800^ADN,36,20^FDMacks Fabricating^FS^XZ"

    'Create an instance of ZPLPrinter class
    Using myZPLPrinter = New ZPLPrinter("LICENSE OWNER", "LICENSE KEY")
        'Set printer DPI
        'The DPI value to be set must match the value for which 
        'the ZPL commands to be processed were created!!!
        myZPLPrinter.Dpi = 203
        'Apply antialiasing?
        myZPLPrinter.AntiAlias = true
        'set label size e.g. 4in x 6in
        myZPLPrinter.LabelWidth = (4 * myZPLPrinter.Dpi)
        myZPLPrinter.LabelHeight = (6 * myZPLPrinter.Dpi)
        'Set image or doc format for output rendering 
        myZPLPrinter.RenderOutputFormat = RenderOutputFormat.PNG
        'Set ZPL commands to be processed...
        Dim buffer = myZPLPrinter.ProcessCommands(zplCommands, enc)
        ' the buffer variable contains the binary output of the ZPL rendering result
        ' The format of this buffer depends on the RenderOutputFormat property setting
        If ((Not (buffer) Is Nothing)  _
                    AndAlso (buffer.Count > 0)) Then
            'Save output rendering to PDF
            System.IO.File.WriteAllBytes("c:\temp\sample-zpl-label.png", buffer(0))
        End If
    End Using

Catch ex As Exception
    Throw ex
End Try

Handling multiple labels generation

Depending on the commands you specify for being processed, they could make the ZPLPrinter Emulator SDK to generate more than one output rendering.

  • For PDF output format, the output rendering will be a single PDF buffer containing as many pages as labels that were generated.

  • For PNG, JPG & PCX output formats, the output rendering will be a list of byte arrays, one array per labels that were generated.

The following sample code shows how to save them for the image formats e.g. for JPG. The specified commands will generate 3 label images.

C# - Handling multiple labels generation

using Neodynamic.SDK.ZPLPrinter;

//...

try
{

    //The ZPL commands to be rendered...
    string zplCommands = "^XA^POI^FT761,320^A0I,56,55^FDOlive Oil^FS^BY4,3,160^FT761,91^BCI,,Y,N^FDOO2935^FS^FO47,281^GB719,0,8^FS^XZ^XA^POI^FT761,320^A0I,56,55^FDCurry Sauce^FS^BY4,3,160^FT761,91^BCI,,Y,N^FDCS4948^FS^FO47,281^GB719,0,8^FS^XZ^XA^POI^FT761,320^A0I,56,55^FDMozzarella^FS^BY4,3,160^FT761,91^BCI,,Y,N^FDMZ1027^FS^FO47,281^GB719,0,8^FS^XZ";

    //Create an instance of ZPLPrinter class
    using (var myZPLPrinter = new ZPLPrinter("LICENSE OWNER", "LICENSE KEY"))
    {
        //Set printer DPI
        //The DPI value to be set must match the value for which 
        //the ZPL commands to be processed were created!!!
        myZPLPrinter.Dpi = 203;
        //Apply antialiasing?
        myZPLPrinter.AntiAlias = true;
        //set label size e.g. 4in x 2in
        myZPLPrinter.LabelWidth = 4 * myZPLPrinter.Dpi;
        myZPLPrinter.LabelHeight = 2 * myZPLPrinter.Dpi;
        //Set image or doc format for output rendering 
        myZPLPrinter.RenderOutputFormat = RenderOutputFormat.JPG;
        //Set ZPL commands to be processed...
        var buffer = myZPLPrinter.ProcessCommands(zplCommands, enc);

        // the buffer variable contains the binary output of the ZPL rendering result
        // The format of this buffer depends on the RenderOutputFormat property setting
        if (buffer != null && buffer.Count > 0)
        {
            //save images on disk 
            for(int i = 0; i < buffer.Count; i++)
            {
                System.IO.File.WriteAllBytes(@"c:\temp\sample-zpl-label-" + i.ToString().PadLeft(buffer.Count, '0') + ".jpg", buffer[i]);
            }
        }
    }
}
catch (Exception ex)
{
    throw ex;
}

VB - Handling multiple labels generation


Imports Neodynamic.SDK.ZPLPrinter
'...
Try 
    'The ZPL commands to be rendered...
    Dim zplCommands As String = "^XA^POI^FT761,320^A0I,56,55^FDOlive Oil^FS^BY4,3,160^FT761,91^BCI,,Y,N^FDOO2935^FS^FO47,281^GB719,0,8^FS^XZ^XA^POI^FT761,320^A0I,56,55^FDCurry Sauce^FS^BY4,3,160^FT761,91^BCI,,Y,N^FDCS4948^FS^FO47,281^GB719,0,8^FS^XZ^XA^POI^FT761,320^A0I,56,55^FDMozzarella^FS^BY4,3,160^FT761,91^BCI,,Y,N^FDMZ1027^FS^FO47,281^GB719,0,8^FS^XZ"

    'Create an instance of ZPLPrinter class
    Using myZPLPrinter = New ZPLPrinter("LICENSE OWNER", "LICENSE KEY")
        'Set printer DPI
        'The DPI value to be set must match the value for which 
        'the ZPL commands to be processed were created!!!
        myZPLPrinter.Dpi = 203
        'Apply antialiasing?
        myZPLPrinter.AntiAlias = true
        'set label size e.g. 4in x 2in
        myZPLPrinter.LabelWidth = (4 * myZPLPrinter.Dpi)
        myZPLPrinter.LabelHeight = (2 * myZPLPrinter.Dpi)
        'Set image or doc format for output rendering 
        myZPLPrinter.RenderOutputFormat = RenderOutputFormat.JPG
        'Set ZPL commands to be processed...
        Dim buffer = myZPLPrinter.ProcessCommands(zplCommands, enc)
        ' the buffer variable contains the binary output of the ZPL rendering result
        ' The format of this buffer depends on the RenderOutputFormat property setting
        If ((Not (buffer) Is Nothing)  _
                    AndAlso (buffer.Count > 0)) Then
            'save images on disk 
            Dim i As Integer = 0
            Do While (i < buffer.Count)
                System.IO.File.WriteAllBytes(("c:\temp\sample-zpl-label-"  _
                                + (i.ToString.PadLeft(buffer.Count, ChrW(48)) + ".jpg")), buffer(i))
                i = (i + 1)
            Loop
        End If
    End Using

Catch ex As Exception
    Throw ex
End Try

Advanced Samples for Web & Desktop Projects

ZPLPrinter Emulator SDK installer package will install a set of sample projects for ASP.NET Web as well as for Desktop apps including morfe advanced settings and usage. The same projects are also available in the following repo https://github.com/neodynamic/ZPL-Printer-Emulator-SDK

Need Assistance?

  • For tech assistance please contact our Support Team
Back to top Copyright © 2003- Neodynamic SRL
http://www.neodynamic.com