.NET HELP

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

Published December 24, 2023
Share:

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 can be used as alternative to BinaryKits.Zpl.

In this article, we will convert ZPL code to PDF because most printer does not support ZPL code but PDF is supported by all printer even the printers from Zebra technologies. The PDF Library we will use to convert ZPL to PDF is IronPDF.

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, and 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;
class Program
{
    static void Main()
    {
        // Instantiate ZplViewer
        var zplViewer = new ZplViewer();
        // Load ZPL file
        zplViewer.LoadFile("path/to/your/label.zpl");
        // Display the ZPL content
        Console.WriteLine(zplViewer.GetContent());
        // Close the viewer
        zplViewer.Close();
    }
}
using BinaryKits.Zpl.Viewer;
class Program
{
    static void Main()
    {
        // Instantiate ZplViewer
        var zplViewer = new ZplViewer();
        // Load ZPL file
        zplViewer.LoadFile("path/to/your/label.zpl");
        // Display the ZPL content
        Console.WriteLine(zplViewer.GetContent());
        // Close the viewer
        zplViewer.Close();
    }
}
Imports BinaryKits.Zpl.Viewer
Friend Class Program
	Shared Sub Main()
		' Instantiate ZplViewer
		Dim zplViewer As New ZplViewer()
		' Load ZPL file
		zplViewer.LoadFile("path/to/your/label.zpl")
		' Display the ZPL content
		Console.WriteLine(zplViewer.GetContent())
		' Close the viewer
		zplViewer.Close()
	End Sub
End Class
VB   C#

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 printer supports 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;
// Initialize ZPL elements and printer storage
IPrinterStorage printerStorage = new PrinterStorage();
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.592000000000006,23.142^PW0^LL0^A0N,36,36^FB620,10,0,C,0^FDTest will go here^FS^FO8.931999999999999,6.09^GB798.196,1205.82,3,B^FS^FO190.008,247.25400000000002^BQN,^PW0^LL02,10,Q,7^FDQA,False^FS^XZ");
// Iterate through label information and draw ZPL elements
foreach (var labelInfo in analyzeInfo.LabelInfos)
{
    var imageData = drawer.Draw(labelInfo.ZplElements);
    File.WriteAllBytes("label.png", imageData);
}
// Retrieve image files and convert to PDF
var response = Directory.EnumerateFiles("").Where(f => f.EndsWith("label.png"));
ImageToPdfConverter.ImageToPdf(response).SaveAs("zpl.pdf");
using BinaryKits.Zpl.Viewer;
using System.IO;
using IronPdf;
using System.Linq;
// Initialize ZPL elements and printer storage
IPrinterStorage printerStorage = new PrinterStorage();
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.592000000000006,23.142^PW0^LL0^A0N,36,36^FB620,10,0,C,0^FDTest will go here^FS^FO8.931999999999999,6.09^GB798.196,1205.82,3,B^FS^FO190.008,247.25400000000002^BQN,^PW0^LL02,10,Q,7^FDQA,False^FS^XZ");
// Iterate through label information and draw ZPL elements
foreach (var labelInfo in analyzeInfo.LabelInfos)
{
    var imageData = drawer.Draw(labelInfo.ZplElements);
    File.WriteAllBytes("label.png", imageData);
}
// Retrieve image files and convert to PDF
var response = Directory.EnumerateFiles("").Where(f => f.EndsWith("label.png"));
ImageToPdfConverter.ImageToPdf(response).SaveAs("zpl.pdf");
Imports BinaryKits.Zpl.Viewer
Imports System.IO
Imports IronPdf
Imports System.Linq
' Initialize ZPL elements and printer storage
Private printerStorage As IPrinterStorage = New PrinterStorage()
Private drawer = New ZplElementDrawer(printerStorage)
' Initialize ZPL analyzer and analyze ZPL code
Private analyzer = New ZplAnalyzer(printerStorage)
Private analyzeInfo = analyzer.Analyze("^XA ^MMT ^PW812 ^LL0203 ^LS0^FO0,0^A0N,36,36^FB600,1,0,L,0^FD^FS ^FO53.592000000000006,23.142^PW0^LL0^A0N,36,36^FB620,10,0,C,0^FDTest will go here^FS^FO8.931999999999999,6.09^GB798.196,1205.82,3,B^FS^FO190.008,247.25400000000002^BQN,^PW0^LL02,10,Q,7^FDQA,False^FS^XZ")
' Iterate through label information and draw ZPL elements
For Each labelInfo In analyzeInfo.LabelInfos
	Dim imageData = drawer.Draw(labelInfo.ZplElements)
	File.WriteAllBytes("label.png", imageData)
Next labelInfo
' Retrieve image files and convert to PDF
Dim response = Directory.EnumerateFiles("").Where(Function(f) f.EndsWith("label.png"))
ImageToPdfConverter.ImageToPdf(response).SaveAs("zpl.pdf")
VB   C#

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 offer 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 showcase the innovation and versatility achievable in modern .NET development. For more examples of ZPL and project supports visit here.

IronPDF offers free trial license that is a great opportunity for users to get to know its functionality. Image to PDF Tutorial using IronPDF can be found here.

< PREVIOUS
Blazor .NET 8 (Developer Tutorial)
NEXT >
C# Destructor (How it Works For Developers)

Ready to get started? Version: 2024.10 just released

Free NuGet Download Total downloads: 11,308,499 View Licenses >