我尝试使用zpl II将扩展代码页850个字符打印到斑马S4M。每当使用扩展字符(即ASCII值>127)之一时,我会得到一个灰色渐变框,而不是实际值。
我正在打印_和_?(alt+0177和alt+0176)。我怀疑我试图使用的是rawprinterhelper(从MS下载,另一个从codeproject下载),但是我看不到字符代码哪里出错了。
奇怪的是,直接从记事本打印会呈现正确的字符,这让我相信这是原始打印机助手类的问题。
我不一定要使用原始打印机帮助程序类,因此如果有更好的方法,我会非常高兴看到它们。
ZPLII样品
没有转义字符
^XA
^FO30,200^AD^FH,18,10^FD35 ± 2 ° ^FS
^FS
^XZ
使用转义字符(尝试使用大写和小写)
^XA
^FO30,200^AD^FH,18,10^FD35 _b0 2 _b1 ^FS
^FS
^XZ
原始打印机帮助程序
[StructLayout(LayoutKind.Sequential)]
public struct DOCINFO
{
[MarshalAs(UnmanagedType.LPWStr)]
public string printerDocumentName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pOutputFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string printerDocumentDataType;
}
public class RawPrinter
{
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
public static extern long OpenPrinter(string pPrinterName, ref IntPtr phPrinter, int pDefault);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
public static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long StartPagePrinter(IntPtr hPrinter);
[
DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long WritePrinter(IntPtr hPrinter, string data, int buf, ref int pcWritten);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long EndPagePrinter(IntPtr hPrinter);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long EndDocPrinter(IntPtr hPrinter);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long ClosePrinter(IntPtr hPrinter);
public static void SendToPrinter(string printerJobName, string rawStringToSendToThePrinter,
string printerNameAsDescribedByPrintManager)
{
IntPtr handleForTheOpenPrinter = new IntPtr();
DOCINFO documentInformation = new DOCINFO();
int printerBytesWritten = 0;
documentInformation.printerDocumentName = printerJobName;
documentInformation.printerDocumentDataType = "RAW";
OpenPrinter(printerNameAsDescribedByPrintManager, ref handleForTheOpenPrinter, 0);
StartDocPrinter(handleForTheOpenPrinter, 1, ref documentInformation);
StartPagePrinter(handleForTheOpenPrinter);
WritePrinter(handleForTheOpenPrinter, rawStringToSendToThePrinter, rawStringToSendToThePrinter.Length,
ref printerBytesWritten);
EndPagePrinter(handleForTheOpenPrinter);
EndDocPrinter(handleForTheOpenPrinter);
ClosePrinter(handleForTheOpenPrinter);
}
}
接受答案的实际修复
设置字符国际化(代码
CI27
)代码页1252。
^XA
^FO30,200^AD^CI27^FH,18,10^FD35 _b0 2 _b1 ^FS
^FS
^XZ