Skip to footer content
.NET HELP

BinaryKits.Zpl.Viewer (How it Works For Developers)

Zebra Programming Language (ZPL) is a printer description language that is primarily used for printing labels on Zebra label printers developed by Zebra Technologies. It provides a set of ZPL II data commands that allow users to format and control the file content to be printed on labels, such as text, barcodes, label width, and graphics along with print preview capability. Developed by Zebra Technologies, it is widely used in industries where precise and standardized labeling is crucial, such as manufacturing, logistics, and healthcare.

In various applications, ZPL is employed to generate labels dynamically, ensuring accurate and consistent printing for a variety of purposes. It is particularly popular in scenarios where batch printing, serialization, or customization of labels is required. Now that we have a brief understanding of ZPL, let's delve into BinaryKits.Zpl.Viewer, a tool designed to facilitate the visualization and analysis of ZPL printer driver code. Also, the Labelary API for ZPL viewing can be used as an alternative to BinaryKits.Zpl.

In this article, we will convert ZPL code to PDF because most printers do not support ZPL code, but PDF is supported by all printers, even those from Zebra Technologies. The PDF Library we will use to convert ZPL to PDF is IronPDF - the .NET PDF Library.

1. Exploring BinaryKits.Zpl.Viewer

In the realm of ZPL, one tool that stands out is the BinaryKits.Zpl Viewer. This viewer is designed to provide developers with a comprehensive solution for visualizing and analyzing ZPL code. It serves as a valuable resource for understanding how ZPL commands will be interpreted and executed on Zebra printers with Zebra labels.

The BinaryKits.Zpl Viewer offers a user-friendly interface that allows developers to send ZPL raw command code and instantly see the visual representation of the single label or tag. This ZPL feature is particularly useful for debugging and fine-tuning ZPL scripts, ensuring that the printed output aligns with the intended design.

1.1. Key Features

1.1.1. ZPL File Visualization

BinaryKits.Zpl.Viewer allows users to open and view ZPL files, providing a comprehensive and organized display of the label content. It renders ZPL commands in a readable format, making it easier to interpret and troubleshoot label designs.

1.1.2. Syntax Highlighting

The viewer incorporates syntax highlighting to distinguish between different elements of the ZPL code, enhancing code readability and making it more accessible for users.

1.1.3. Interactive Preview

Users can interactively preview label designs within the BinaryKits.Zpl.Viewer interface. This feature helps in understanding how the label will appear when printed, aiding in the design and debugging process.

1.1.4. Error Detection

BinaryKits.Zpl.Viewer includes error detection capabilities, identifying potential issues within the ZPL code. This assists users in quickly identifying and rectifying errors before sending the code to the Zebra printer.

2. How to Use

To utilize BinaryKits.Zpl.Viewer effectively, follow these steps:

2.1. Open ZPL File

Launch the BinaryKits.Zpl.Viewer application and open the desired file using the built-in file explorer.

2.2. Navigate and Analyze

Navigate through the ZPL code using the viewer's user-friendly interface. Leverage features such as syntax highlighting and interactive preview to comprehend the label design.

2.3. Code Example

Here's a simple example of using BinaryKits.Zpl.Viewer in C#:

using BinaryKits.Zpl.Viewer;
using System;

class Program
{
    static void Main()
    {
        // Instantiate ZplViewer
        var zplViewer = new ZplViewer();

        // Load the ZPL file
        zplViewer.LoadFile("path/to/your/label.zpl");

        // Display the ZPL content in the console
        Console.WriteLine(zplViewer.GetContent());

        // Close the viewer after use
        zplViewer.Close();
    }
}
using BinaryKits.Zpl.Viewer;
using System;

class Program
{
    static void Main()
    {
        // Instantiate ZplViewer
        var zplViewer = new ZplViewer();

        // Load the ZPL file
        zplViewer.LoadFile("path/to/your/label.zpl");

        // Display the ZPL content in the console
        Console.WriteLine(zplViewer.GetContent());

        // Close the viewer after use
        zplViewer.Close();
    }
}
Imports BinaryKits.Zpl.Viewer
Imports System

Friend Class Program
	Shared Sub Main()
		' Instantiate ZplViewer
		Dim zplViewer As New ZplViewer()

		' Load the ZPL file
		zplViewer.LoadFile("path/to/your/label.zpl")

		' Display the ZPL content in the console
		Console.WriteLine(zplViewer.GetContent())

		' Close the viewer after use
		zplViewer.Close()
	End Sub
End Class
$vbLabelText   $csharpLabel

This example demonstrates how to use the BinaryKits.Zpl.Viewer library to load a ZPL file, retrieve its content, and then close the viewer.

By incorporating BinaryKits.Zpl.Viewer into your workflow, you can streamline the development and troubleshooting of Zebra label printing applications.

4. IronPDF and Its Features

IronPDF is a powerful library for handling PDF documents in .NET applications. It facilitates the creation, modification, and manipulation of PDF files, offering developers a robust set of tools to integrate PDF functionality seamlessly into their projects.

Some notable features of IronPDF include the ability to create PDF documents from scratch, convert HTML and images to PDF, extract text and images from PDFs, and add annotations and form fields to existing PDFs. Its versatility makes it an excellent choice for developers working on applications that require PDF generation and manipulation.

5. Convert ZPL Data into Images and Images to PDF using IronPDF

Now, let's explore how BinaryKits.Zpl.Viewer can be seamlessly integrated with IronPDF to convert ZPL-generated labels into PDFs. The provided code example demonstrates a step-by-step process using both libraries. This example is a simple creation of maximum number labels and its PDF representation because not all printers support ZPL code. The .NET libraries used in this example are BinaryKits.Zpl.Viewer and IronPDF.

using BinaryKits.Zpl.Viewer;
using System.IO;
using IronPdf;
using System.Linq;

class Program
{
    static void Main()
    {
        // Initialize printer storage for ZPL elements
        IPrinterStorage printerStorage = new PrinterStorage();

        // Create an instance of ZplElementDrawer using the printer storage
        var drawer = new ZplElementDrawer(printerStorage);

        // Initialize ZPL analyzer and analyze ZPL code
        var analyzer = new ZplAnalyzer(printerStorage);
        var analyzeInfo = analyzer.Analyze("^XA ^MMT ^PW812 ^LL0203 ^LS0^FO0,0^A0N,36,36^FB600,1,0,L,0^FD^FS ^FO53.592,23.142^PW0^LL0^A0N,36,36^FB620,10,0,C,0^FDTest will go here^FS^FO8.932,6.09^GB798.196,1205.82,3,B^FS^FO190.008,247.254^BQN,^PW0^LL02,10,Q,7^FDQA,False^FS^XZ");

        // Iterate through label information and draw ZPL elements
        foreach (var labelInfo in analyzeInfo.LabelInfos)
        {
            // Draw the ZPL elements into an image
            var imageData = drawer.Draw(labelInfo.ZplElements);

            // Write the image data to a PNG file
            File.WriteAllBytes("label.png", imageData);
        }

        // Retrieve image files and convert them to a single PDF
        var imageFiles = Directory.EnumerateFiles("").Where(f => f.EndsWith("label.png"));
        ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("zpl.pdf");
    }
}
using BinaryKits.Zpl.Viewer;
using System.IO;
using IronPdf;
using System.Linq;

class Program
{
    static void Main()
    {
        // Initialize printer storage for ZPL elements
        IPrinterStorage printerStorage = new PrinterStorage();

        // Create an instance of ZplElementDrawer using the printer storage
        var drawer = new ZplElementDrawer(printerStorage);

        // Initialize ZPL analyzer and analyze ZPL code
        var analyzer = new ZplAnalyzer(printerStorage);
        var analyzeInfo = analyzer.Analyze("^XA ^MMT ^PW812 ^LL0203 ^LS0^FO0,0^A0N,36,36^FB600,1,0,L,0^FD^FS ^FO53.592,23.142^PW0^LL0^A0N,36,36^FB620,10,0,C,0^FDTest will go here^FS^FO8.932,6.09^GB798.196,1205.82,3,B^FS^FO190.008,247.254^BQN,^PW0^LL02,10,Q,7^FDQA,False^FS^XZ");

        // Iterate through label information and draw ZPL elements
        foreach (var labelInfo in analyzeInfo.LabelInfos)
        {
            // Draw the ZPL elements into an image
            var imageData = drawer.Draw(labelInfo.ZplElements);

            // Write the image data to a PNG file
            File.WriteAllBytes("label.png", imageData);
        }

        // Retrieve image files and convert them to a single PDF
        var imageFiles = Directory.EnumerateFiles("").Where(f => f.EndsWith("label.png"));
        ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("zpl.pdf");
    }
}
Imports BinaryKits.Zpl.Viewer
Imports System.IO
Imports IronPdf
Imports System.Linq

Friend Class Program
	Shared Sub Main()
		' Initialize printer storage for ZPL elements
		Dim printerStorage As IPrinterStorage = New PrinterStorage()

		' Create an instance of ZplElementDrawer using the printer storage
		Dim drawer = New ZplElementDrawer(printerStorage)

		' Initialize ZPL analyzer and analyze ZPL code
		Dim analyzer = New ZplAnalyzer(printerStorage)
		Dim analyzeInfo = analyzer.Analyze("^XA ^MMT ^PW812 ^LL0203 ^LS0^FO0,0^A0N,36,36^FB600,1,0,L,0^FD^FS ^FO53.592,23.142^PW0^LL0^A0N,36,36^FB620,10,0,C,0^FDTest will go here^FS^FO8.932,6.09^GB798.196,1205.82,3,B^FS^FO190.008,247.254^BQN,^PW0^LL02,10,Q,7^FDQA,False^FS^XZ")

		' Iterate through label information and draw ZPL elements
		For Each labelInfo In analyzeInfo.LabelInfos
			' Draw the ZPL elements into an image
			Dim imageData = drawer.Draw(labelInfo.ZplElements)

			' Write the image data to a PNG file
			File.WriteAllBytes("label.png", imageData)
		Next labelInfo

		' Retrieve image files and convert them to a single PDF
		Dim imageFiles = Directory.EnumerateFiles("").Where(Function(f) f.EndsWith("label.png"))
		ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("zpl.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

This code is written in C# and uses the BinaryKits.Zpl.Viewer library to convert Zebra Programming Language (ZPL) code into a visual representation in the form of PNG images, and then combines these images into a single PDF document. Here's a brief explanation of the code:

  1. Library Imports: The code starts by importing necessary libraries, including BinaryKits.Zpl.Viewer, IronPDF, and System.IO.
  2. Initialization: It initializes elements for ZPL printing and storage using the IPrinterStorage interface and a ZplElementDrawer. The ZplAnalyzer is also set up to analyze ZPL code.
  3. ZPL Analysis: The provided ZPL code is analyzed using the ZplAnalyzer. The analysis result, stored in analyzeInfo, includes information about various ZPL elements in the code.
  4. Image Drawing: The code then iterates through the label information obtained from the analysis and uses the ZplElementDrawer to draw ZPL elements onto an image. Each image is saved as a PNG file named "label.png."
  5. PDF Conversion: After saving individual PNG images, the code retrieves the list of image files in the current directory with names ending in "label.png." It then uses the IronPDF library to convert these PNG files into a single PDF document named "zpl.pdf."

Output Label Image

BinaryKits.Zpl.Viewer (How It Works For Developers): Figure 1 - Image Output

Output Label PDF

BinaryKits.Zpl.Viewer (How It Works For Developers): Figure 2 - PDF Output

4. Conclusion

In conclusion, the combination of BinaryKits.Zpl.Viewer and IronPDF offers a powerful solution for developers working with ZPL in .NET applications. The viewer enhances the development process by providing a visual representation of ZPL code, aiding in debugging and comprehension. When integrated with IronPDF, the transition from ZPL-generated labels to PDF documents becomes smooth and efficient, expanding the possibilities for creating sophisticated labeling solutions in various industries. As technology continues to advance, the synergy between libraries like BinaryKits.Zpl.Viewer and IronPDF showcases the innovation and versatility achievable in modern .NET development. For more examples of ZPL and project support visit the BinaryKits.Zpl GitHub Repository.

IronPDF offers a free trial license for developers that is a great opportunity for users to get to know its functionality. A detailed Image to PDF conversion tutorial using IronPDF can guide developers in implementing this functionality in their applications.

Frequently Asked Questions

What is BinaryKits.Zpl.Viewer and how does it work for developers?

BinaryKits.Zpl.Viewer is a tool that helps developers visualize and analyze ZPL (Zebra Programming Language) printer driver code. It provides a user-friendly interface to input ZPL code and see the visual representation of labels, aiding in debugging and fine-tuning ZPL scripts.

How can I convert ZPL-generated labels into PDF documents?

You can integrate BinaryKits.Zpl.Viewer with IronPDF to convert ZPL-generated labels into PDF documents. This integration allows you to compile ZPL code into PNG images and then use IronPDF to create a PDF, making it easy to handle and share label designs.

What are the key features of BinaryKits.Zpl.Viewer?

The key features of BinaryKits.Zpl.Viewer include ZPL file visualization, syntax highlighting, interactive preview, and error detection. These features enhance the readability of ZPL code, assist in debugging, and ensure accurate label designs.

How does BinaryKits.Zpl.Viewer aid in debugging ZPL code?

BinaryKits.Zpl.Viewer aids in debugging by providing an interactive preview of the ZPL code, highlighting syntax, and detecting errors. This allows developers to identify and correct issues before the code is sent to the printer.

Can BinaryKits.Zpl.Viewer be used in industries that require precise labeling?

Yes, industries such as manufacturing, logistics, and healthcare can benefit from using BinaryKits.Zpl.Viewer due to their need for precise and standardized labeling, which the viewer facilitates through its comprehensive visualization and analysis capabilities.

Is there an alternative tool for viewing ZPL code?

Yes, the Labelary API is an alternative tool for visualizing and analyzing ZPL code. It offers similar functionalities for previewing ZPL labels, providing developers with additional options for ZPL code handling.

How can IronPDF enhance the functionality of BinaryKits.Zpl.Viewer?

IronPDF enhances the functionality of BinaryKits.Zpl.Viewer by enabling the conversion of ZPL-generated images into PDF documents. This is particularly useful as PDFs are widely supported across different platforms and devices, facilitating easy distribution and use of label designs.

Where can I find more resources and examples for BinaryKits.Zpl.Viewer?

Developers can find more resources, documentation, and code examples on the BinaryKits.Zpl GitHub Repository, which offers comprehensive support and insights into using the viewer effectively.

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of ...Read More