Search code examples
javaandroidbluetoothzebra-printers

Printing UTF-8 characters on bluetooth printer


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.


Solution

  • Unicode isn't supported in the CPCL language. You can do it in ZPL though, and the iMZ supports ZPL. Check out this link.