如何在斑马打印机上使用 win-1250 代码页进行打印?
我有用于使用 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
是我从 此处。
我的问题是只打印 ASCII 字符,如下所示:
za g l ja
丢失了非 ASCII 字符。
有趣的是,当我打开记事本并将相同的文本放入其中并在 Zebra 打印机上打印时,所有字符都正常。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不同之处在于记事本使用打印机驱动程序,您绕过它。 Zebra 打印机支持使用其内置字体。它有代码页 950 的字符集以及所谓的“Latin 1”和“Latin 9”。关键问题是它们都不包含您需要的字形。打印机驱动程序通过向打印机发送图形而不是字符串来解决此问题。编程手册 在这里 顺便说一句。
我想这些打印机有某种安装额外字体的选项,如果不是这样的话,很难在世界其他地方进行销售。请联系您友好的打印机供应商以获取支持和选项。
The difference is that Notepad is using the printer driver, you are bypassing it. Zebra printers have some support for using its built-in fonts. It's got character sets for codepage 950 and something it calls "Latin 1" and "Latin 9". Key problem is that none of them contain the glyphs you need. The printer driver solves this problem by sending graphics to the printer, not strings. The programming manual is here btw.
I would imagine that these printers have some kind of option to install additional fonts, hard to make the sale in the rest of the world if that wouldn't be the case. Contact your friendly printer vendor for support and options.
我发现 Wireshark 来自 ZebraDesigner 的字符集是 UTF-8,因此尝试将字符串转换为 byte[] 作为 utf-8
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(sw.ToString());
像 ěščřžýáíé 这样的捷克字符现在可以了
I found with Wireshark that charset from ZebraDesigner is UTF-8 so try to convert string to byte[] as utf-8
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(sw.ToString());
czech chars like as ěščřžýáíé is now OK
如果您需要向打印机添加自定义字符,请查看我制作的补丁对于夏普斑马。修改它以添加对那些缺失字母的支持应该很简单。
If you need to add custom characters to your printer, take a look at the patch I made for SharpZebra. It should be trivial to modify it to add support for those missing letters.
我在类中添加了一个辅助方法,该方法会将字符串(默认为
UTF-16
)转换为UTF-8
编码的byte[] 然后打印它。
I added a helper method to my class that would convert a string (which is by default
UTF-16
) into aUTF-8
encodedbyte[]
and then print that.