Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting character code table to print non-latin characters in ESC/POS printer

I have an Android app and I'm trying to print some texts with it that contain non-latin characters.

I'm using this code to send ESC t n command to the printer:

 byte[] buf = new byte[]{0x1B, 0x74, (byte)2}; // 2 is the codetable for PC850: Multilingual
 this.mBaseOutputStream.write(buf);

Then, I try to print my code like this:

this.mBaseOutputStream.write("Лорем ăîîîîîîă".getBytes("cp850"));

But all I get for the non-latin characters are weird symbols. So what am I doing wrong?

like image 691
Alexandru Pufan Avatar asked May 04 '18 11:05

Alexandru Pufan


1 Answers

Not sure this is an answer as such, but hopefully this will get things started. Also need a bit of room to explain...

It looks like code page 850 doesn't have the characters needed. An easy way to check this offline is to convert back to a String. E.g. :

System.out.println(
        new String("Лорем ăîîîîîîă".getBytes("cp850"), "cp850"));
--> ????? ?îîîîîî?

Clearly only the î is available there.

You may need to do some experiments with alternative code pages - what type of printer is this?

A couple of tests here suggest the example string may need more than one code page, but someone else may know better:

System.out.println(
        new String("Лорем ăîîîîîîă".getBytes("cp852"), "cp852"));
--> ????? ăîîîîîîă
System.out.println(
        new String("Лорем ăîîîîîîă".getBytes("cp855"), "cp855"));
--> Лорем ????????
like image 103
df778899 Avatar answered Sep 20 '22 13:09

df778899