我正在尝试使用Zebra Z6Mplus打印机上的ZPL以不同的标签打印一系列图像。我使用这样的指示:
"^XA" + "^MNY" + "~DYE:LOGO,P,P," + binaryData.Length + ",," + zplImageData + "^XZ";
"^XA^FO10,10^IME:LOGO.PNG^FS^XZ";
"^XA^IDE:LOGO.PNG^XZ";
C#代码:
public void printUSB()
{
string zplImageData = string.Empty;
//Make sure no transparency exists. I had some trouble with this. This PNG has a white background
string filePath = @"TEST.png";
byte[] binaryData = System.IO.File.ReadAllBytes(filePath);
foreach (Byte b in binaryData)
{
string hexRep = String.Format("{0:X}", b);
if (hexRep.Length == 1)
hexRep = "0" + hexRep;
zplImageData += hexRep;
}
string printerName = GetPrinterName();
string sendGraph= "^XA" + "^MNY" + "~DYE:LOGO,P,P," + binaryData.Length + ",," + zplImageData + "^XZ";
string printLabel = "^XA^FO10,10^IME:LOGO.PNG^FS^XZ";
string clear = "^XA^IDE:LOGO.PNG^XZ";
RawPrinterHelper.SendStringToPrinter(printerName, clear);
Thread.Sleep(2000);
RawPrinterHelper.SendStringToPrinter(printerName, sendGraph);
Thread.Sleep(5000);
RawPrinterHelper.SendStringToPrinter(printerName, printLabel);
Thread.Sleep(2000);
RawPrinterHelper.SendStringToPrinter(printerName, clear);
Thread.Sleep(2000);
}
我不知道为什么,但是我的代码有时有效,有时却无效。我添加了“睡眠”行,但有时仍可以打印出良好的标签,有时仍可以打印空白标签。
在代码更改之前,它只打印相同的标签,因为打印机将图像存储在内存中。我已经添加了^ ID命令,但是现在它有时会打印空白标签,而不是好的图像。
我不知道为什么。请帮忙。
谢谢,迈克