Search code examples
javascriptencodingprintingzebra-printers

Encoding date in Zebra printer


I need to encode "date field" in my Zebra M4Plus printer from UTF-8 to UTF-16. For this I need to use "required translation table". In documentation I found this:

~DER:JIS.DAT,27848,300021213001...

But I don-t know what is JIS.DAT and why 27848.

This is my code example:

qz.append("^XA");
qz.append("^FO160,635");
qz.append("^A@R,30,30,E:TT0003M_.FNT");
qz.append("~DER:.DAT,27848,Данные для вывода^FS"); - it not work. Printer go to offline.

Who has experience with this, help please.


Solution

  • Please try forcing the Java applet to use Cyrilic: qz.setEncoding("cp1251"); or qz.setEncoding("windows-1251"); unless the printer natively supports UTF-16, then qz.setEncoding("UTF-16");

    Update: In newer versions of QZ Tray, the syntax is qz.configs.create("My Printer", { encoding: 'UTF-8' });

    Also, make sure to define <meta charset="utf-8"> in your web page.

    Edit: There's a detailed explanation of what causes this here: Printer ZebraZ4MPlus don't print Russian Cirillyc character

    Java has a habit of assuming what character set you want to use, which is often cp1252 (Windows) or UTF-8 (*nix). Depending on which encoding the printer is expecting (and which encodings it supports), Java first needs to translate these characters/commands to a suitable equivalent before sending. A full list of encodings supported by Java 7 is available here.

    A very similar question was posed on the qz bug tracker in regards to Greek character support. The trick was to tell both Java as well as the printer which language/character encoding was being used.

    Finally, I've had scenarios where the BOM flag (Byte Order Mark) on the html/js file has caused undesirable results. In that case, JavaScript was aware of the document's encoding and translation was occurring before sending to Java. I use Notepad++ to switch UTF-8 BOM on/off.

    In addition, here is the link to the qz bug report, which is in regards to a different printing language (ESCP instead of ZPL), but has a similar symptom of the output from Java getting transposed incorrectly for his printer. https://code.google.com/p/jzebra/issues/detail?id=204#c10

    -Tres