我正在尝试使用 ZPL II 将扩展代码页 850 个字符打印到 Zebra S4M。每当使用一个扩展字符 IE ASCII 值 > 127 时,我都会得到一个不同灰度的框,而不是实际值。
我正在尝试打印 ± 和 °(ALT+0177 和 ALT+0176)。我怀疑它是我正在尝试使用的 RawPrinterHelper(从 MS 下载,另一个从 CodeProject 下载)但是我看不出字符代码哪里出错了。
奇怪的是,直接从记事本打印会呈现正确的字符,这让我相信这是原始打印机助手类的问题。
我不喜欢使用 Raw Printer Helper 类,所以如果有更好的方法,我很高兴看到它们。
SAMPLE 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