Printing UTF-8 characters on bluetooth printer

Morten picture Morten · Aug 14, 2013 · Viewed 15k times · Source

I have an application where I should be able to print on a bluetooth printer, Zebra iMZ320, but I have some problems with UTF-8 specific characters (Æ, Ø or Å).

I am connecting to the device as follows:

        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddr);
        Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { Integer.TYPE });
        bSocket = (BluetoothSocket)m.invoke(device, new Object[] { Integer.valueOf(1) });
        bSocket.connect();
        outStream = bSocket.getOutputStream();
        inStream = bSocket.getInputStream();

After the socket is open, I am sending the data in CPCL:

        String cpclData = "! U1 SETLP 5 2 24 \r\n"+text+"\r\n";
        outStream.write(cpclData.getBytes());
        outStream.flush();

But when I am trying to print the mentioned characters, it writes some abnormal characters instead.

I contacted Zebra, and one of their engineers wrote that I should try the following:

! 0 200 200 80 1 
IN-MILLIMETERS 
JOURNAL 
CENTER 
COUNTRY NORWAY
TEXT 4 0 0 8 COUNTRY IS NORWAY OR DENMARK
TEXT 4 0 0 15 Æ Ø Å
PRINT

But it does absolutely nothing.

Answer

código picture código · Apr 24, 2014

it is simple if you try to print a label from android device; when you write the data use "ISO-8859-1" encoding, look:

String cpclData = "! U1 SETLP 5 2 24 \r\n"+text+"\r\n";
outStream.write(EncodingUtils.getBytes(cpclData, "ISO-8859-1"));
outStream.flush();