C# 如何在zebra打印机上使用win-1250代码页打印?
我用Zebra打印机打印此代码(具体为RW 420)C# 如何在zebra打印机上使用win-1250代码页打印?,c#,utf-8,zebra-printers,zpl,epl,C#,Utf 8,Zebra Printers,Zpl,Epl,我用Zebra打印机打印此代码(具体为RW 420) RawPrinterHelper是我从微软得到的课程 我的问题是,只有ASCII字符是这样打印的: za g l ja 缺少非ASCII字符 有趣的是,当我打开记事本,将相同的文本放入其中,并在Zebra打印机上打印时,所有字符都正常。不同之处在于记事本使用的是打印机驱动程序,而您正在绕过它。Zebra打印机支持使用内置字体。它有代码页950的字符集,它称之为“拉丁1”和“拉丁9”。关键问题是它们都不包含您需要的标志符号。打
RawPrinterHelper
是我从微软得到的课程
我的问题是,只有ASCII字符是这样打印的:
za g l ja
缺少非ASCII字符
有趣的是,当我打开记事本,将相同的文本放入其中,并在Zebra打印机上打印时,所有字符都正常。不同之处在于记事本使用的是打印机驱动程序,而您正在绕过它。Zebra打印机支持使用内置字体。它有代码页950的字符集,它称之为“拉丁1”和“拉丁9”。关键问题是它们都不包含您需要的标志符号。打印机驱动程序通过向打印机发送图形而不是字符串来解决此问题。编程手册顺便说一句
我可以想象,这些打印机可以选择安装额外的字体,如果不是这样的话,很难在世界其他地方销售。请与友好的打印机供应商联系以获取支持和选项。如果需要向打印机添加自定义字符,请查看我为SharpZebra制作的。修改它以添加对丢失字母的支持应该很简单。我在Wireshark中发现ZebraDesigner中的字符集是UTF-8,所以尝试将字符串转换为字节[]作为UTF-8
byte[]bytes=System.Text.Encoding.UTF8.GetBytes(sw.ToString())代码>
捷克字符(如a滁řžýáé)现在可以了我在我的类中添加了一个helper方法,它可以将字符串(默认情况下是UTF-16
)转换为UTF-8
编码的字节[]
,然后打印出来
public static bool SendUtf8StringToPrinter(string szPrinterName, string szString)
{
// by default System.String is UTF-16 / Unicode
byte[] bytes = Encoding.Unicode.GetBytes(szString);
// convert this to UTF-8. This is a lossy conversion and you might lose some chars
bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, bytes);
int bCount = bytes.Length;
// allocate some unmanaged memory
IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(bCount);
// copy the byte[] into the memory pointer
System.Runtime.InteropServices.Marshal.Copy(bytes, 0, ptr, bCount);
// Send the converted byte[] to the printer.
SendBytesToPrinter(szPrinterName, ptr, bCount);
// free the unmanaged memory
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr);
// it worked! Happy cry.
return true;
}
这听起来像是一个编码问题。您是否尝试过转换为其他编码,如UTF-8或ISO-8859-1?缺少的字符是来自win-1250或ISO-8859-2字符集的波兰语字符,我在编码中尝试了这两种方法。转换方法…您能否解决此问题?这里也有同样的问题。根据epl手动命令I8,B,048应该将代码页设置为win-1250,它根本没有效果。我会和供应商讨论这个问题,但我有点希望其他一些非英语的speeking开发者也有同样的问题,并以某种方式解决;)顺便说一句,我有时羡慕说英语的开发者;)如果没有所有的编码,我的生活会轻松得多;)
public static bool SendUtf8StringToPrinter(string szPrinterName, string szString)
{
// by default System.String is UTF-16 / Unicode
byte[] bytes = Encoding.Unicode.GetBytes(szString);
// convert this to UTF-8. This is a lossy conversion and you might lose some chars
bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, bytes);
int bCount = bytes.Length;
// allocate some unmanaged memory
IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(bCount);
// copy the byte[] into the memory pointer
System.Runtime.InteropServices.Marshal.Copy(bytes, 0, ptr, bCount);
// Send the converted byte[] to the printer.
SendBytesToPrinter(szPrinterName, ptr, bCount);
// free the unmanaged memory
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr);
// it worked! Happy cry.
return true;
}