【发布时间】:2011-01-12 14:34:12
【问题描述】:
我有此代码用于使用 Zebra 打印机(具体为 RW 420)进行打印
StringBuilder sb = new StringBuilder();
sb.AppendLine("N");
sb.AppendLine("q609");
sb.AppendLine("Q203,26");
//set printer character set to win-1250
sb.AppendLine("I8,B,001");
sb.AppendLine("A50,50,0,2,1,1,N,\"zażółć gęślą jaźń\"");
sb.AppendLine("P1");
printDialog1.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
byte[] bytes = Encoding.Unicode.GetBytes(sw.ToString());
bytes = Encoding.Convert(Encoding.Unicode, Encoding.GetEncoding(1250), bytes);
int bCount = bytes.Length;
IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(bCount);
System.Runtime.InteropServices.Marshal.Copy(bytes, 0, ptr, bytes.Length);
Common.RawPrinterHelper.SendBytesToPrinter(printDialog1.PrinterSettings.PrinterName, ptr, bCount);
}
RawPrinterHelper 是我从 here 获得的 Microsoft 课程。
我的问题是只有 ASCII 字符是这样打印的:
za g l ja
缺少非 ASCII 字符。
有趣的是,当我打开记事本并将相同的文本放入其中并在 Zebra 打印机上打印时,所有字符都可以。
【问题讨论】:
-
这听起来像是一个编码问题。您是否尝试过转换为其他编码,例如 UTF-8 或 ISO-8859-1?
-
缺少的字符是来自 win-1250 或 iso-8859-2 字符集的波兰字符,我在 Encoding.Convert 方法中都尝试过...
-
你能解决这个问题吗?同样的问题在这里。
标签: c# utf-8 zebra-printers zpl epl