Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 214
MBX Avatar asked Mar 22 '23 18:03

MBX


2 Answers

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();
like image 93
código Avatar answered Apr 01 '23 11:04

código


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

like image 35
Ovi Tisler Avatar answered Apr 01 '23 12:04

Ovi Tisler