Md. Zakir Hossain
Md. Zakir Hossain

Reputation: 1092

How to Print Unicode (Bangla Font) to Thermal Printer?

I want to Print Bangla text Like "আপনি কি ডাটা সংরক্ষন করতে চান" from my android app.But i got wrong result every time. Here is my Output:

enter image description here

My Code is Here:

   String memo = "আপনি কি ডাটা সংরক্ষন করতে চান" + "\n" +
            "\n" +
            "\n" +
            "\n" +
            "\n" +
            "\n";

    byte[] buffer = memo.getBytes(Charset.forName("UTF-8"));


    try {
        Toast.makeText(getApplicationContext(), "Starting...", Toast.LENGTH_LONG).show();

        Thread.sleep(1000);
        byte[] printformat = {27, 33, 01};
        mmOutputStream.write(printformat);
        mmOutputStream.write(buffer);
        mmOutputStream.write(0x0B);
        mmOutputStream.write(0x0B);
        mmOutputStream.write(0x0B);
        mmOutputStream.flush();

        mmOutputStream.close();
        mmSocket.close();
        Toast.makeText(getApplicationContext(), "Completed", Toast.LENGTH_LONG).show();
        mmOutputStream.close();
        mmSocket.close();
    } catch (Exception ex) {
        Toast.makeText(getApplicationContext(),
                "Excep IntentPrint", Toast.LENGTH_SHORT).show();
  }

Upvotes: 0

Views: 3377

Answers (3)

user2786685
user2786685

Reputation:

Check it in your printer's datasheet.

for example, My printer HOP-E200 58mm Mini Portable Thermal Printer datasheet says

enter image description here

Upvotes: 0

Joop Eggen
Joop Eggen

Reputation: 109597

This assumes that the printer can handle multi-byte sequences of UTF-8. At the same time printer specific control bytes are written. I think the printer has only a limited and specific ASCII (8 bit) character set.

So try it out:

byte[] buffer = new byte[128];
for (int i = 0; i < 128; ++i) {
    buffer[i] = (byte)(-128 + i);
}

If you cannot find some documentation, you need to map all by hand.

And then you need to map characters in strings like "\u098F\u09AC\u0982" to their byte values.

Map<Character, Byte> charsToByte;
charsToByte.put('\u088F', (byte)129); // Or such.

Upvotes: 0

Shuvo
Shuvo

Reputation: 86

First of all please check the printer has bangla font support. if not then another way you can print. you need to capture the layout which has the bangla text as image (bitmap) then use the printers bitmap printing api. I had the same problem for arabic text. i solve this problem using this technique. thanks.

Upvotes: 3

Related Questions