Printing UTF-8 characters on bluetooth printer
Solution 1
Unicode isn't supported in the CPCL language. You can do it in ZPL though, and the iMZ supports ZPL. Check out this link.
Solution 2
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();
Solution 3
In my case, it worked perfectly the solution provided by @jsanmarb but using the Code page 850 (Latin-1 - Western European languages) found here: https://www.ascii-codes.com/cp850.html
Related videos on Youtube
MBX
Updated on September 20, 2022Comments
-
MBX over 1 year
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.
-
Charles about 10 yearsIf you're going to copy and paste someone else's code you should link to the original source as well.
-
Gaurav Gupta about 10 years
Unicode isn't supported in the CPCL language
. Is this documented somewhere. It would be nice if you can provide the link. -
Ali_Waris about 7 yearsFor hindi fonts, even using this prints junk characters. :(
-
andreszs over 3 yearsThis is the right way to set the encoding. Unfortunately some chinese generic printers don't use the right alphabet and still print rubbish when using non-western european language like greek or russian.