.NET 幫助

BinaryKits.Zpl.Viewer(開發者工作原理)

發佈 2023年12月24日
分享:

斑馬程式語言 (ZPL) 是一種列印描述語言,主要用於 Zebra Technologies 開發的 Zebra 標籤印表機上列印標籤。它提供一系列 ZPL ii 資料命令,允許使用者格式化和控制要在標籤上列印的檔案內容,如文字、條碼、標籤寬度和圖形,並具有列印預覽功能。由 Zebra Technologies 開發,廣泛應用於製造業、物流業和醫療保健等需要精確和標準化標籤的行業。

在各種應用中,ZPL 被用來動態生成標籤,確保為各種用途準確且一致的列印。它特別受歡迎於需要批量列印、序列化或標籤定制的情境。現在我們對 ZPL 有了一個簡要的了解,讓我們深入了解 BinaryKits.Zpl.Viewer,這是一個用於便於視覺化和分析 ZPL 印表機驅動程式碼的工具。此外, Labelary API 可以用作 BinaryKits.Zpl 的替代方案。

在本文中,我們將 ZPL 代碼轉換為 PDF,因為大多數印表機不支援 ZPL 代碼,但 PDF 是所有印表機甚至 Zebra Technologies 印表機都支援的格式。我們將用來將 ZPL 轉換為 PDF 的 PDF 庫是 IronPDF.

1. 探索 BinaryKits.Zpl.Viewer

在 ZPL 領域中,一個突出的工具是 BinaryKits.Zpl Viewer。這個查看器旨在為開發者提供一個全面的解決方案,用於可視化和分析 ZPL 代碼。它是一個理解 ZPL 命令如何在使用 Zebra 標籤的 Zebra 打印機上解釋和執行的寶貴資源。

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 代碼中的潛在問題。這有助於用戶在將代碼發送到 Zebra 打印機之前快速識別和糾正錯誤。

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
VB   C#

這個範例展示如何使用 BinaryKits.Zpl.Viewer 庫來載入 ZPL 檔案、檢索其內容,並且隨後關閉檢視器。

透過將 BinaryKits.Zpl.Viewer 納入工作流程,您可以精簡 Zebra 標籤列印應用程式的開發和故障排除過程。

4. IronPDF 及其特點

IronPDF 是一個強大的庫,用於在 .NET 應用程序中處理 PDF 文檔。它便於創建、修改和操作 PDF 文件,為開發者提供了一套強大的工具,讓 PDF 功能能夠無縫地整合到他們的專案中。

IronPDF 的一些顯著特點包括從頭創建 PDF 文檔,將 HTML 和圖像轉換為 PDF,從 PDF 中提取文字和圖像,並在現有 PDF 上添加註釋和表單欄位。它的多功能性使其成為需要生成和操作 PDF 的應用程序開發者的絕佳選擇。

5. 使用 IronPDF 將 ZPL 數據轉換為圖像和圖像轉換為 PDF

現在,讓我們來探討如何將 BinaryKits.Zpl.Viewer 無縫整合至 IronPDF 以便將 ZPL 生成的標籤轉換為 PDF。提供的代碼示例展示了使用這兩個庫的逐步過程。這個示例創建了最大數量的標籤及其 PDF 表示,因為並非所有的打印機都支持 ZPL 代碼。這個範例中使用的 .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")
VB   C#

這段程式碼是用 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輸出

4. 結論

總之,BinaryKits.Zpl.Viewer 和 IronPDF 的組合為在 .NET 應用程式中處理 ZPL 的開發者提供了一個強大的解決方案。這個查看器通過提供 ZPL 代碼的視覺表示來增強開發過程,有助於除錯和理解。當與 IronPDF 集成時,從 ZPL 生成的標籤轉換為 PDF 文件變得順暢且高效,擴展了在各行各業中創建複雜標籤解決方案的可能性。隨著技術的不斷進步,像 BinaryKits.Zpl.Viewer 和 IronPDF 之間的協同效應展示了在現代 .NET 開發中可實現的創新和多樣性。更多 ZPL 的範例和項目支援,請訪問 這裡IronPDF 提供 免費試用授權 這是讓用戶了解其功能的一個絕佳機會。使用 IronPDF 的圖像轉 PDF 教程可以找到 這裡.

< 上一頁
Blazor .NET 8(開發人員教程)
下一個 >
C# 解構函式(開發人員如何使用)

準備開始了嗎? 版本: 2024.10 剛剛發布

免費 NuGet 下載 總下載次數: 10,993,239 查看許可證 >