Skip to content

Raw Encoding

Lite edited this page Jun 12, 2018 · 70 revisions

Compatibility

  • ✅ 2.1 | ✅ 2.0 | ⛔ 1.9 | ...

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
ESCPOS French Spanish Italian Portuguese German Greek Vietnamese Simplified, Traditional

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 this does not work and you get strange characters, try 'CP850'; The Epson TM-T20 programming guide, for example, claims to support 1252, but it actually supports cp850

var data = [
   /* Toggle WPC1252 in ESCPOS */
   '\x1B' + '\x74' + '\x10',

   /* 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',

   /* 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 = [
   '\x1B' +  '\x74' + '\x30' + // TOGGLE TCVN-3-1

   /* 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',  //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',   //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

Clone this wiki locally