AlexSmith AlexSmith - 5 months ago 23
Javascript Question

Printer ZebraZ4MPlus don't print Russian Cirillyc character

I try to print some text in Russian from JavaScript using applet "qz-print". My js code:

if (qz !== null) {
qz.append("^LH5, 80");
qz.append("^FO160,220^AUR,5,10^FD" + Черноморец + "^FS");

In this variant I use zpl encoding CI29. But my printer after this code go to offline... Help only reboot computer and printer.

When I send the next code - all OK:

qz.append("^LH5, 80");
qz.append("^FO120,110^ATR,5,10^FD" + Черноморец + "^FS");

But printer print the strange characters instead "Черноморец" similar to KOI8-R.

Who knows how to print on Russian?


Please see this thread: Encoding date in Zebra printer

The solution is 3 parts, which includes:

  1. Proper translation table (special ZPL command) e.g. ^CI17, ^CI14, etc.
  2. Document encoding of your JavaScript file to be encoded UTF-8 if you want to use Unicode Characters directly (optionally you can use Unicode escaping format, but for most programmers, it's not needed as the .js file is already UTF-8 by default)
  3. Tell Java (in this case qz) to use the correct encoding. What worked for the previous person was qz.setEncoding("UTF-16"); although CP-1251 may render success as well.

What makes this particularly difficult is the character translation and fonts can be switched three times without you knowing it.

First Encoding Gotcha

JavaScript will default to the encoding of the .js file itself (usually UTF-8, but can be ANSI among many others. Notepad++ will display this from the "Encoding" menu option).

Second Encoding Gotcha

Java will internally use UTF-16 but then without any warning to the user, Java will do a character conversion when it's being written "raw", which on Windows would be converted to CP-1252, discarding many of the UTF-16 characters. This conversion is VERY good ONLY IF the encoding has characters that are mapable (i.e. CP-1251 has many Cyrillic characters that map well to and from Unicode). For this reason, qz intentionally echo's a message in the logs about the default encoding, which you should see if in the Java Console, once activated: INFO: Current printer charset encoding: windows-1252

Third Encoding Gotcha

In my experience most printers supports Cyrillic, but depending on the age of the printer, may need a compatible code page OR a font uploaded, etc, which is all very specific from the vendor. In the case of receipt printers, the code pages are very inconsistent. Luckily for you Zebra offers fantastic technical support and quick turn-around for these questions.

How we figured this out

In the case of the thread linked above, a Zebra developer (Jason) helped with the printer portion, and a QZ developer (myself) helped with the Java portion. Jason emailed me directly to help with this issue.

I hope this explanation helps you and many others. Please mark this thread as answered if it fixes your issue, or contact the qz community support if you have further questions in regards to raw printing.