A .net library helping to generate ZPL string. Please refer to the Programming Guide for raw ZPL code definitaion, ZPL Documentation
⚠️ Note we are changing the class name prefix, fromZPLElement
in version 1.x toBinaryKits.Zpl.Label.Elements
in version 3. The documentation for the old version 1 is available here
Package Manager | .NET CLI |
---|---|
PM> install-package BinaryKits.Zpl.Label |
> dotnet add package BinaryKits.Zpl.Label |
This library supports following elements:
Element | Informations |
---|---|
Barcode | ANSI Codabar, Code 30, Code 128, EAN-13, Interleaved 2 of 5 |
QR-Code | - |
Image | DownloadObjects, DownloadGraphics |
Text | TextBlock, TextField, FieldBlock, SingleLineFieldBlock |
Drawing | GraphicBox, DiagonalLine, Circle, Ellipse |
Yes, you can test the generated ZPL code via http://labelary.com/viewer.html
For example, the data can be transmitted to the printer IpAddress on port 9100.
var zplData = @"^XA^MMP^PW300^LS0^LT0^FT10,60^APN,30,30^FH\^FDSAMPLE TEXT^FS^XZ";
// Open connection
var tcpClient = new System.Net.Sockets.TcpClient();
tcpClient.Connect("10.10.5.85", 9100);
// Send Zpl data to printer
var writer = new System.IO.StreamWriter(tcpClient.GetStream());
writer.Write(zplData);
writer.Flush();
// Close Connection
writer.Close();
tcpClient.Close();
Also, a Virutal Printer for Zebra is available as Chrome Plugin
using BinaryKits.Zpl.Label;
using BinaryKits.Zpl.Label.Elements;
var output = new ZplGraphicBox(100, 100, 100, 100).ToZplString();
Console.WriteLine(output);
var output = new ZplBarcode128("123ABC", 10, 50).ToZplString();
Console.WriteLine(output);
var sampleText = "[_~^][LineBreak\n][The quick fox jumps over the lazy dog.]";
var font = new ZplFont(fontWidth: 50, fontHeight: 50);
var elements = new List<ZplElementBase>();
elements.Add(new ZplTextField(sampleText, 50, 100, font));
elements.Add(new ZplGraphicBox(400, 700, 100, 100, 5));
elements.Add(new ZplGraphicBox(450, 750, 100, 100, 50, LineColor.White));
elements.Add(new ZplGraphicCircle(400, 700, 100, 5));
elements.Add(new ZplGraphicDiagonalLine(400, 700, 100, 50, 5));
elements.Add(new ZplGraphicDiagonalLine(400, 700, 50, 100, 5));
elements.Add(new ZplGraphicSymbol(GraphicSymbolCharacter.Copyright, 600, 600, 50, 50));
// Add raw Zpl code
elements.Add(new ZplRaw("^FO200, 200^GB300, 200, 10 ^FS"));
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { AddEmptyLineBeforeElementStart = true });
Console.WriteLine(output);
var elements = new List<ZplElementBase>();
var origin = new ZplOrigin(100, 100);
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
elements.Add(new ZplGraphicBox(origin.PositionX, origin.PositionY, 50, 50));
origin = origin.Offset(0, 100);
}
origin = origin.Offset(100, -300);
}
var options = new ZplRenderOptions();
var output = new ZplEngine(elements).ToZplString(options);
Console.WriteLine(output);
var elements = new List<ZplElementBase>();
elements.Add(new ZplGraphicBox(400, 700, 100, 100, 5));
var options = new ZplRenderOptions { SourcePrintDpi = 203, TargetPrintDpi = 300 };
var output = new ZplEngine(elements).ToZplString(options);
Console.WriteLine(output);
var elements = new List<ZplElementBase>();
var textField = new ZplTextField("AAA", 50, 100, ZplConstants.Font.Default);
textField.Comments.Add("An important field");
elements.Add(textField);
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { DisplayComments = true });
Console.WriteLine(output);
var sampleText = "[_~^][LineBreak\n][The quick fox jumps over the lazy dog.]";
var font = new ZplFont(fontWidth: 50, fontHeight: 50);
var elements = new List<ZplElementBase>();
// Special character is repalced with space
elements.Add(new ZplextField(sampleText, 10, 10, font, useHexadecimalIndicator: false));
// Special character is repalced Hex value using ^FH
elements.Add(new ZplTextField(sampleText, 10, 50, font, useHexadecimalIndicator: true));
// Only the first line is displayed
elements.Add(new ZplSingleLineFieldBlock(sampleText, 10, 150, 500, font));
// Max 2 lines, text exceeding the maximum number of lines overwrites the last line.
elements.Add(new ZplFieldBlock(sampleText, 10, 300, 400, font, 2));
// Multi - line text within a box region
elements.Add(new ZplTextBlock(sampleText, 10, 600, 400, 100, font));
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { AddEmptyLineBeforeElementStart = true });
Console.WriteLine(output);
For the best image result, first convert your graphic to black and white. The library auto resize the image based on DPI.
You have 2 possibilities to transfer the graphic to the printer:
With this option, the image is sent to the printer in the original graphic format and the printer converts the graphic to a black and white graphic
var elements = new List<ZplElementBase>();
elements.Add(new ZplDownloadObjects('R', "SAMPLE.BMP", System.IO.File.ReadAllBytes("sample.bmp")));
elements.Add(new ZplImageMove(100, 100, 'R', "SAMPLE", "BMP"));
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { AddEmptyLineBeforeElementStart = true, TargetPrintDpi = 300, SourcePrintDpi = 200 });
Console.WriteLine(output);
With this option, the image is converted from the library into a black and white graphic and the printer already receives the finished print data
var elements = new List<ZplElementBase>();
elements.Add(new ZplDownloadGraphics('R', "SAMPLE", System.IO.File.ReadAllBytes("sample.bmp")));
elements.Add(new ZplRecallGraphic(100, 100, 'R', "SAMPLE"));
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { AddEmptyLineBeforeElementStart = true, TargetPrintDpi = 600, SourcePrintDpi = 200 });
Console.WriteLine(output);
Manufacturer | Simulator |
---|---|
Zebra Technologies | - |
Honeywell International Inc | ZSIM |
Avery Dennison | MLI (Monarch Language Interpreter) |
cab Produkttechnik GmbH & Co. KG | |
AirTrack | |
SATO | SZPL |
printronix | ZGL |
Toshiba Tec | |
GoDEX | GZPL |
Language | Project |
---|---|
JavaScript | JSZPL |
.NET | sharpzebra |
.NET | PDFtoZPL |