.NET 帮助

BinaryKits.Zpl.Viewer(开发者如何使用)

斑马编程语言 (ZPL) 是一种打印机描述语言,主要用于在由斑马技术公司开发的 Zebra 标签打印机上打印标签。 它提供了一套 ZPL II 数据命令,允许用户格式化和控制要打印在标签上的文件内容,如文本、BarCode、标签宽度和图形以及打印预览功能。 该工具由斑马技术公司(Zebra Technologies)开发,广泛应用于制造、物流和医疗保健等需要精确和标准化标签的行业。

在各种应用中,ZPL 被用来动态生成标签,以确保各种用途的打印准确一致。 在需要批量打印、序列化或定制标签的情况下,它尤其受欢迎。 既然我们已经对 ZPL 有了简单的了解,那就让我们深入了解一下 BinaryKits.Zpl.Viewer,这是一款旨在促进 ZPL 打印机驱动程序代码可视化和分析的工具。 此外,Labelary API for ZPL viewing 可以作为 BinaryKits.Zpl 的替代方案使用。

在本文中,我们将把 ZPL 代码转换为 PDF,因为大多数打印机不支持 ZPL 代码,但所有打印机都支持 PDF,即使是斑马技术公司的打印机。 我们将用来将 ZPL 转换为 PDF 的 PDF 库是 IronPDF - the .NET PDF Library

1.探索 BinaryKits.Zpl.Viewer

在ZPL领域,一个突出的工具是BinaryKits.Zpl Viewer。 该查看器旨在为开发人员提供可视化和分析 ZPL 代码的综合解决方案。 它是了解 ZPL 命令如何在带有斑马标签的斑马打印机上解释和执行的宝贵资源。

BinaryKits.Zpl Viewer 提供了一个用户友好型界面,允许开发人员发送 ZPL 原始命令代码,并立即查看单个标签或标记的可视化表示。 该 ZPL 功能对于调试和微调 ZPL 脚本特别有用,可确保打印输出与预期设计一致。

1.1.主要特点

1.1.1.ZPL 文件可视化

BinaryKits.Zpl.Viewer 允许用户打开和查看 ZPL 文件,全面、有序地显示标签内容。 它以可读格式呈现 ZPL 命令,使标签设计的解释和故障排除更加容易。

1.1.2.语法高亮

该阅读器采用语法高亮显示,以区分 ZPL 代码的不同元素,从而提高代码的可读性,使用户更容易阅读。

1.1.3.互动预览

用户可以在BinaryKits.Zpl.Viewer界面中交互式预览标签设计。 该功能有助于理解标签在打印时的显示效果,有助于设计和调试过程。

1.1.4.错误检测

BinaryKits.Zpl.Viewer 包括错误检测功能,可识别 ZPL 代码中的潜在问题。 这有助于用户在将代码发送到斑马打印机之前快速识别和纠正错误。

2.如何使用

要有效使用 BinaryKits.Zpl.Viewer,请遵循以下步骤:

2.1.打开 ZPL 文件

启动 BinaryKits.Zpl.Viewer 应用程序,使用内置文件浏览器打开所需文件。

2.2.导航和分析

使用查看器的用户友好界面浏览 ZPL 代码。 利用语法高亮和交互式预览等功能来理解标签设计。

2.3.代码示例

下面是一个在 C# 中使用 BinaryKits.Zpl.Viewer 的简单示例:

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
$vbLabelText   $csharpLabel

本示例演示了如何使用 BinaryKits.Zpl.Viewer 库加载 ZPL 文件、检索其内容并关闭查看器。

通过将 BinaryKits.Zpl.Viewer 纳入工作流程,您可以简化斑马标签打印应用程序的开发和故障排除。

4.IronPDF 及其功能

IronPDF 是一个功能强大的库,用于在 .NET 应用程序中处理 PDF 文档。 它便于创建、修改和操作 PDF 文件,为开发人员提供了一套强大的工具,可将 PDF 功能无缝集成到他们的项目中。

IronPDF 的一些显著功能包括:从零开始创建 PDF 文档、将 HTML 和图像转换为 PDF、从 PDF 中提取文本和图像,以及为现有 PDF 添加注释和表单域。 对于开发需要生成和处理 PDF 的应用程序的开发人员来说,它的多功能性使其成为一个绝佳的选择。

5.使用 IronPDF 将 ZPL 数据转换为图像和图像转换为 PDF

现在,让我们来探讨 BinaryKits.Zpl.Viewer 如何与 IronPDF 无缝集成,将 ZPL 生成的标签转换为 PDF。 所提供的代码示例演示了使用这两个库的逐步过程。 由于并非所有打印机都支持 ZPL 代码,因此本示例只是简单创建了最大数字标签及其 PDF 表示法。 本例中使用的 .NET 库是 BinaryKits.Zpl.Viewer 和 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")
$vbLabelText   $csharpLabel

此代码使用C#编写,并使用BinaryKits.Zpl.Viewer库将Zebra编程语言(ZPL)代码转换为PNG图像形式的可视化表示,然后将这些图像合并为单个PDF文档。 以下是代码的简要说明:

  1. 库导入: 代码首先导入必要的库,包括 BinaryKits.Zpl.Viewer、IronPDF 和 System.IO。

  2. 初始化:它使用IPrinterStorage接口和ZplElementDrawer为ZPL打印和存储初始化元素。 ZplAnalyzer 也被设置为分析 ZPL 代码。

  3. ZPL分析: 使用ZplAnalyzer对提供的ZPL代码进行分析。 存储在analyzeInfo中的分析结果包括代码中各种ZPL元素的信息。

  4. 图像绘制: 然后,代码遍历从分析中获得的标签信息,并使用ZplElementDrawer将ZPL元素绘制到图像上。 每张图片都保存为名为 "label.png "的 PNG 文件。

  5. PDF 转换:保存单个 PNG 图像后,代码会检索当前目录中名称以“label.png”结尾的图像文件列表。然后,它使用 IronPDF 库将这些 PNG 文件转换为名为“zpl.pdf”的单个 PDF 文档。

输出标签图像

BinaryKits.Zpl.Viewer(如何为开发人员工作):图 1 - 图像输出

输出标签 PDF

BinaryKits.Zpl.Viewer(开发人员如何使用):图2 - PDF输出

结论

总之,BinaryKits.Zpl.Viewer 和 IronPDF 的结合为在 .NET 应用程序中使用 ZPL 的开发人员提供了强大的解决方案。 该阅读器提供 ZPL 代码的可视化表示,有助于调试和理解,从而增强开发过程。 与 IronPDF 集成后,从 ZPL 生成的标签到 PDF 文档的过渡变得流畅高效,为各行各业创建复杂的标签解决方案拓展了可能性。 随着技术的不断进步,BinaryKits.Zpl.Viewer 和 IronPDF 等库之间的协同作用展示了现代 .NET 开发中可实现的创新性和多功能性。 有关更多 ZPL 示例和项目支持,请访问BinaryKits.Zpl GitHub 仓库

IronPDF 为开发者提供免费试用许可证,这是让用户了解其功能的绝佳机会。 使用IronPDF的图像转PDF转换教程可以指导开发人员在他们的应用程序中实现此功能。

Chipego
软件工程师
Chipego 拥有出色的倾听技巧,这帮助他理解客户问题并提供智能解决方案。他在 2023 年加入 Iron Software 团队,此前他获得了信息技术学士学位。IronPDF 和 IronOCR 是 Chipego 主要专注的两个产品,但他对所有产品的了解每天都在增长,因为他不断找到支持客户的新方法。他喜欢 Iron Software 的合作氛围,公司各地的团队成员贡献他们丰富的经验,以提供有效的创新解决方案。当 Chipego 离开办公桌时,你经常可以发现他在看书或踢足球。
< 前一页
Blazor .NET 8 (开发者教程)
下一步 >
C# 析构函数(开发人员如何使用)