Print Unicode Characters to POS printer

Ringo picture Ringo · Mar 26, 2015 · Viewed 9.4k times · Source

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!

Answer

circular picture circular · Jan 24, 2018

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