将Unicode字符打印到POS打印机 [英] Print Unicode Characters to POS printer
问题描述
我正在尝试将我的语言字符打印到POS打印机.打印机可以很好地打印,但是效果很差.这是我尝试过的:
I'm trying to print my language characters to a POS printer. The Printer prints well but the result's so bad. This is what I tried:
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter bw = new BinaryWriter(ms))
{
bw.Write(AsciiControlChars.Escape);
bw.Write('@');
//ESCCMD.RenderBitmap(bw, logo);
bw.Write("Đây là Tiếng Việt");
bw.Write(AsciiControlChars.Escape);
bw.Write('d');
bw.Write((byte)3);
// Feed 3 vertical motion units and cut the paper with a 1 point uncut
bw.Write(AsciiControlChars.GroupSeparator);
bw.Write(AsciiControlChars.V);
bw.Write((byte)66);
bw.Write((byte)3);
bw.Flush();
RawPrinterHelper.SendToSerialPort(ms.ToArray(), txtPortTest.Text, Convert.ToInt32(cbbBaudRate.SelectedValue));
}
那么如何使用ESC/POS命令打印我的语言字符? 非常感谢!
So how can I print my language characters using ESC/POS command? Thanks so much!
推荐答案
在打印国际字符之前,需要检查您的特定型号是否支持相应的代码页,然后使用ESC t
命令进行设置.可在此处获得EPSON打印机支持的代码页列表和命令语法信息:
Before printing international characters you need to check if your specific model supports the corresponding codepage and then set it with the ESC t
command. The list of supported code pages for EPSON printers and the command syntax info is available here: https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=32 (registration required)
例如,要打印希腊(ISO-8859-7)文本,您需要执行以下操作:
For example, in order to print Greek (ISO-8859-7) text, you need to do something like this:
private void PrintGreekIsoText(BinaryWriter bw, string text)
{
// ESC t 15
bw.Write("\x1bt\x15");
// Convert the text to the appropriate encoding
var isoEncoding = Encoding.GetEncoding(28597);
var bytes = Encoding.Unicode.GetBytes(text);
byte[] output = Encoding.Convert(Encoding.Unicode, isoEncoding, bytes);
bw.Write(output);
}
这篇关于将Unicode字符打印到POS打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!