2

I am trying to print arabic string in escpos from android java. But only some chinese characters are printing. My printer supports arabic language.

Here my code

private void printArabic() throws IOException {
    String print ="الجحيم";

    ByteBuffer init = ByteBuffer.allocate(2);
    init.put((byte) 0x1B);
    init.put((byte) 0x25);
    sendData(init.array(), outputStream);

    ByteBuffer dataToPrint = ByteBuffer.allocate(print.length());
    dataToPrint.put(print.getBytes("cp864"));
    sendData(dataToPrint.array(), outputStream);


}
private void sendData(byte[] buffer, OutputStream os) throws IOException
{
    try {
        ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
        os.write(byteBuffer.array());
        os.flush();
        // tell the user data were sent

    } catch (Exception e) {
        e.printStackTrace();
    }
}

It will be helpfull if someone can suggest any code sample.

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
Farah Abbas
  • 39
  • 1
  • 10

2 Answers2

1

Greeting,

Your program is great and works fine.

The problem is the character encoding passed to the printer. Somewhere in the network from your program to the printer, the UTF-8 encoding (java default) is converted to other encoding.

Check the printer default encoding, it might be possible to change. If cannot change default printer encoding, change the java encoding accordingly.

Also if you have a proxy/filter/firewall in the network it might change encoding as well.

Update

Change default printer encoding with operating system printer's default settings.

Change Java encoding answered here.

Community
  • 1
  • 1
Dudi Boy
  • 4,551
  • 1
  • 15
  • 30
0

first you need to convert text to bitmap image then split image to chunk and send it to printer like below :

Print Arabic characters in android Thermal Printer