0

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!

Ringo
  • 3,795
  • 3
  • 22
  • 37
  • What do you mean the result is bad? Is it that the characters are not properly written? Then please make sure that font you're using supports proper characters. – Afzaal Ahmad Zeeshan Mar 26 '15 at 03:53
  • Yes @AfzaalAhmadZeeshan! The characters are not properly written and there is no way to define a font-family in ESC/POS command also. I send the string as raw data to printer. – Ringo Mar 26 '15 at 03:56
  • Are you sure the string encoding is right? try to convert it to string Encoding.Unicode – Hussein Zawawi Mar 26 '15 at 04:02
  • Yes @HusseinZawawi. I tried to convert to Encoding.Unicode and Encoding.UTF8 already. Both of those do not take effect – Ringo Mar 26 '15 at 04:07
  • @HICURIN, did you managed to solve this problem? Would you be kindly to share the solution? – Sam Nov 01 '18 at 13:01
  • @Sam Yes. I managed to solve the problem 2 weeks after I posted the question. You can either try to import languages to your printer(usually doesn’t work :)) or write your own encoding and decoding classes in your language. I did wrote my own encoding and decoding classes in vietnamese. Happy coding! – Ringo Nov 01 '18 at 13:11
  • @HICURIN Well done!!! And thank you for replying. Would you mind to share your code with me? I am having problem at Vietnamese (here is my post https://stackoverflow.com/questions/52715099/c-sharp-esc-pos-print-vietnamese). Would really appreciate if you could help. Thanks... – Sam Nov 01 '18 at 13:25

1 Answers1

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);
}
circular
  • 103
  • 2
  • 8