Wiki - Raw Encoding

Compatibility

Contents

The following guide is to help understand the techniques available for sending a specialized character encoding to a printer device which does not recognize UTF-8. This is for raw printing only.

Language French Spanish Italian Portuguese German Greek Vietnamese Chinese Arabic Russian
ESCPOS French Spanish Italian Portuguese German Greek Vietnamese Simplified, Traditional Arabic Russian
ZPL Simplified

Background

Character encoding, also known as a "codepage" or sometimes "character map" is a raw byte representation of a language's character set. It's much like a custom font with the letters in (what would appear to be) incorrect places.

Why would someone use a codepage instead of UTF-8? Well, put simply, most people wouldn't if they had a choice however the thermal printing industry (as well as several others) still has good, reliable hardware in the wild that doesn't offer UTF-8 support. Chances are if you've received a receipt from a restaurant, store or gas station, it was printed in a raw codepage for your language. For the US, this is often CP-1252, or more formally called Windows-1252.

Java 7 supports about 130 encoding formats which reside in lib/rt.jar and lib/charsets.jar. Choosing the correct codepage is often dependent on strict requirements such as hardware limitations but each character set will have some history behind it which may help understand its usefulness to you or your company.

Character sets often start with CP-xxxx, UTF-xxxx, IBM-xxxx or ISO-xxxx although may have less-obvious names such as Big5 (Traditional Chinese), TCVN-3-1 (Vietnamese), etc. Also, despite a device claiming a character set is supported, the diacritical marks may be incorrectly implemented for a particular language such as CP-1258, or may not render properly due to right-to-left style languages, such as Arabic.


ESCPOS

The following section is written for ESCPOS capable printers. Due to hardware and firmware differences, not all encodings and fonts are available on all ESCPOS compatible hardware. Please consult your hardware manufacturer for determining compatibility.

ESCPOS Western European

Covers French, Spanish, Italian, Portuguese, German

var config = qz.configs.create("Printer name", { encoding: 'Cp1252' });   // Toggle Cp1252 in Java 
/* If 1252 does not work and you get strange characters, try 'Cp850'; The Epson TM-T20 programming guide, for example, claims to support Cp1252, but it actually supports Cp850*/

var data = [
   /* Toggle WPC1252 in ESCPOS */
   '\x1B' + '\x74' + '\x10',   // ESC t 16 = Cp1252
  // '\x1B' + '\x74' + '\x02',   // ESC t 2 = Cp850

   /* Sample French */
   'Voix ambiguë d\'un cœur qui, au zéphyr, préfère les jattes de kiwis\n',

   /* Sample Spanish */
   'Tendré que ir a España. ¿Cómo? Por avion.\n',

   /* Sample Italian */
   'L\'articolo è “uno”. Uno scontrino, perché? Perché la parola inizia per s più consonante.\n',

   /* Sample Portuguese */
   'Luís argüia à Júlia que «brações, fé, chá, óxido, pôr, zângão» eram palavras do português.\n',

   /* Sample German */
   'Köln ist größer als Garmisch Partenkirchen. Der Rhein ist länger als die Mosel.\n',

   /* Line Feeds */
   '\n\n\n\n\n'
];

qz.print(config, data);

ESCPOS Greek

var config = qz.configs.create("Printer Name", { encoding: 'Cp1253' });

var data = [
   /* Toggle Cp1253 in ESCPOS */
   '\x1B' + '\x74' + '\x0E',   // ESC t 14 = Greek (Cp1253)

   /* Sample Greek Text */
   'Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός\n';
];

qz.print(config, data);

ESCPOS Vietnamese

Since 2.0.6

var config = qz.configs.create(printer, {encoding: 'TCVN-3-1'});

var data = [
   /* Toggle TCVN-3-1 in ESCPOS */
   '\x1B' +  '\x74' + '\x30',

   /* Sample Vietnamese */
   'Tiếng Việt, còn gọi tiếng Việt Nam hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam.\n'
];

qz.print(config, data);

ESCPOS Simplified Chinese

Covers Simplified (Mandarin) Chinese

var config = qz.configs.create("Printer Name", {encoding: 'GB2312'});  // *Epson T88 models with correct firmware.  Toggles EUC encoding, Simplified Chinese
                                            // {encoding: 'GBK'});     // Fuken POS90 ships with GB18030, but 'GBK' is required

var printData = [
   '\x1B' + '\x40',  // ESC @ - init command, necessary for proper byte interpretation
   '这句话是简体中文',
   '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
   '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
   '\x1B' + '\x69'          // cut paper
];

qz.print(config, printData);

*Epson TM-T88VI and higher has board capable of firmware update. TM-T88V and lower require special model printer. Please contact official Epson reseller for firmware; incorrect firmware may damage printer. Printer status will read Resident Character: Alphanumeric, Simple Chinese

ESCPOS Traditional Chinese

Covers Traditional (Cantonese) Chinese

var config = qz.configs.create("Printer Name", {encoding: 'Big5'});  // *Epson T88 models with correct firmware.  Toggles Big5 with Hong Kong extensions.
                                            // {encoding: 'GBK'});   // Fuken POS90 ships with GB18030, but 'GBK' is required

var printData = [
   '\x1B' + '\x40',   // ESC @ - init command, necessary for proper byte interpretation
   '艾德蒙 AOC E2450SWH 23.6吋\n',
   ' LED液晶寬螢幕特價$ 19900',
   '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
   '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
   '\x1B' + '\x69'          // cut paper
];

qz.print(config, printData);

*Epson TM-T88VI and higher has board capable of firmware update. TM-T88V and lower require special model printer. Please contact official Epson reseller for firmware; incorrect firmware may damage printer. Printer status will read Resident Character: Alphanumeric, Traditional Chinese

ESCPOS Arabic

Since 2.0.8

Instruct an Epson printer to use IBM864 codepage. Note, this lacks most of the Arabic diacritics which are used in Modern Standard Arabic as well as Dialectal Arabic as well as some additional letters, however, these are often omitted, so IBM864 should be suitable for Arabic characters.

For the Epson printer to recognize IBM864, we had to use a utility to change settings in the printer. More details about this is available here: #339

var config = qz.configs.create("Printer Name", { encoding: "IBM864" });  // Toggle IBM864 in Java 

var printData = [
   '\x1B' + '\x40',   // ESC @ - init command, necessary for proper byte interpretation
   '\x1B' + '\x74' + '\x25', // Setup "codepage 37", which is Epson's IBM864
   'لكن لا بد أن أوضح لك أن كل هذه الأفكار', '\n', // UTF-8 RTL text
   '\x1B' + '\x69'          // cut paper
];

qz.print(config, printData);

ESCPOS Russian

var config = qz.configs.create("Printer Name", { encoding: 'Cp866' });

var data = [
   /* Toggle Cp866 in ESCPOS */
   '\x1B' + '\x74' + '\x11',   // ESC t 17 = Cyrillic #2 (Cp866)

   /* Sample Russian Text */
   'Быстрая коричневая лиса прыгает через ленивую собаку.\n';
];

qz.print(config, data);

ZPL

ZPL Simplified Chinese

Requirements:

Note: The printer will not permanently store the Font Assignment command (^CW) or Encoding table command (^SE) -- if the printer powers off, these settings are lost. Send both of these commands at the beginning of every format or you can use an Autoexec file, which automatically sends these settings when the printer is powered on: ^XA^DFE:AUTOEXEC.ZPL^CW1,E:ANMDS.TTF^SEE:GB.DAT^XZ

var config = qz.configs.create("PrinterName");

var data = [
   '^XA\n',
   '^SEE:GB.DAT^CI28\n', //^SE = set the encoding table & location; ^CI28 = change encoding to UTF-8
   '^CW1,E:ANMDS.TTF\n',     //^CW = set the font identifier & location (Andale font)
   '^FO50,50\n',
   '^A1,50,50\n'
   '^FD Chinese Andale 盒呆艾丙^FS\n',
   '^FO50,200\n',
   '^A1,50,50\n',
   '^FD Zebra 盒呆艾丙^FS\n',
   '^XZ\n'
];

qz.print(config, data);
}
Edit this page