Print Unicode Characters to POS printer

試著忘記壹切 提交于 2019-12-19 05:08:40

问题


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));
                }

So how can I print my language characters using ESC/POS command? Thanks so much!


回答1:


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)

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);
}


来源:https://stackoverflow.com/questions/29270810/print-unicode-characters-to-pos-printer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!