Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/luis3132/tauri-plugin-thermal-printer/llms.txt

Use this file to discover all available pages before exploring further.

Thermal printers are fundamentally byte-stream devices — they receive raw binary data and map each byte to a glyph using a fixed code page stored in their firmware. The plugin’s CodePage configuration controls two separate but related concerns: which code page the printer’s firmware should activate (the ESC t n command), and how the Rust backend should encode your Unicode text strings into the bytes that are sent to the printer.

The CodePage Interface

import { ENCODE, type CodePage } from "tauri-plugin-thermal-printer";

const options: CodePage = {
  code_page: 6,          // required — raw ESC t n value for your printer
  encode: ENCODE.WINDOWS_1252, // optional — defaults to ENCODE.ACCENT_REMOVER
  use_gbk: false,        // optional — defaults to false
};
code_page is the only required field. encode and use_gbk are both optional and have sensible defaults.
FieldTypeRequiredDefaultDescription
code_pagenumber✅ YesRaw ESC t n value sent to the printer (\x1B\x74\x{n}). Look this up in your printer’s programming manual.
encodeEncode❌ NoENCODE.ACCENT_REMOVERHost-side encoding strategy applied before bytes are transmitted.
use_gbkboolean❌ NofalseWhen true, characters that encode cannot represent are retried with GBK before falling back to raw UTF-8 bytes.

How Encoding Works

The encoding pipeline has three stages, applied per character:
1

Primary encoding attempt

If encode is set to a real encoding (e.g. ENCODE.WINDOWS_1252), the character is encoded using that encoding via the encoding_rs library. If encoding succeeds the bytes are emitted directly.
2

GBK retry (if use_gbk is true)

If the primary encoding fails to represent the character and use_gbk is true, the character is re-tried using encoding_rs::GBK. This is useful for mixed-script text where most content is ASCII but occasional Chinese characters appear.
3

UTF-8 passthrough

If all encoding attempts fail (or use_gbk is false), the original UTF-8 bytes for the character are emitted unchanged. Whether the printer renders them correctly depends on its firmware.

ENCODE.ACCENT_REMOVER

ENCODE.ACCENT_REMOVER is the default encoding and the safest choice for printers that lack reliable code-page support for Latin characters with diacritics. Instead of encoding to a specific byte value, it transliterates accented and special characters to their nearest ASCII equivalents before any GBK retry or UTF-8 passthrough:
InputOutput
á, à, â, äa
é, è, ê, ëe
ñn
üu
ßss
EUR
©(c)
ACCENT_REMOVER is not a real character encoding — it is a pre-processing step. After transliteration, any remaining non-ASCII characters that cannot be represented go through the GBK retry (if use_gbk is true) and then the UTF-8 passthrough.

Available ENCODE Values

All other ENCODE.* constants correspond directly to encoding_rs statics and are available under the same uppercase names:
// Windows-1252 — covers most Western European languages
// (French, German, Spanish, Portuguese, Italian, Dutch…)
import { ENCODE } from "tauri-plugin-thermal-printer";

const options = {
  code_page: 6,
  encode: ENCODE.WINDOWS_1252,
};
The full set of available encode values exported by the plugin:
ConstantScript / Region
ENCODE.ACCENT_REMOVERTransliterates to ASCII (plugin-specific)
ENCODE.WINDOWS_1250Central European
ENCODE.WINDOWS_1251Cyrillic
ENCODE.WINDOWS_1252Western European (Latin-1 superset)
ENCODE.WINDOWS_1253Greek
ENCODE.WINDOWS_1254Turkish
ENCODE.WINDOWS_1255Hebrew
ENCODE.WINDOWS_1256Arabic
ENCODE.WINDOWS_1257Baltic
ENCODE.WINDOWS_1258Vietnamese
ENCODE.WINDOWS_874Thai
ENCODE.GBKSimplified Chinese
ENCODE.GB18030Simplified Chinese (superset of GBK)
ENCODE.BIG5Traditional Chinese
ENCODE.SHIFT_JISJapanese
ENCODE.EUC_JPJapanese (Unix)
ENCODE.EUC_KRKorean
ENCODE.ISO_2022_JPJapanese (7-bit)
ENCODE.ISO_8859_2Central European
ENCODE.ISO_8859_3South European / Esperanto
ENCODE.ISO_8859_4North European
ENCODE.ISO_8859_5Cyrillic
ENCODE.ISO_8859_6Arabic
ENCODE.ISO_8859_7Greek
ENCODE.ISO_8859_8Hebrew (visual)
ENCODE.ISO_8859_8_IHebrew (logical)
ENCODE.ISO_8859_10Nordic
ENCODE.ISO_8859_13Baltic Rim
ENCODE.ISO_8859_14Celtic
ENCODE.ISO_8859_15Western European (with €)
ENCODE.ISO_8859_16South-Eastern European
ENCODE.KOI8_RRussian
ENCODE.KOI8_UUkrainian
ENCODE.IBM866Cyrillic (DOS)
ENCODE.MACINTOSHMac Roman
ENCODE.X_MAC_CYRILLICMac Cyrillic
ENCODE.UTF_8Unicode (UTF-8)
ENCODE.UTF_16BEUnicode (UTF-16 Big Endian)
ENCODE.UTF_16LEUnicode (UTF-16 Little Endian)
ENCODE.REPLACEMENTReplacement encoding (security)
ENCODE.X_USER_DEFINEDUser-defined single-byte

Choosing the Right code_page

The code_page value is the raw argument to the ESC t n command sent to your printer. There is no universal standard — each manufacturer assigns their own page numbers. You must look this up in your printer’s programming manual. Common values for popular printer families:
code_page valueEpson/Star (common)Description
0USA / PC437Basic ASCII + box drawing
1KatakanaJapanese half-width katakana
2PC850Multilingual Latin
6PC1252Windows-1252 Western European
17PC866Russian Cyrillic
19PC858Western European (with €)
If you select the wrong code_page, printed text may show garbled characters even if your encode setting is correct — the printer will map each byte to the wrong glyph. Always test with your specific printer model.

The use_gbk Flag

When use_gbk: true is set, any character that the primary encode cannot represent is re-tried using GBK before the plugin falls back to raw UTF-8 bytes. This is useful for:
  • Receipts that are primarily in a Latin encoding but occasionally include Chinese product names
  • Printers that have native GBK support (common in Chinese POS hardware)
import { ENCODE } from "tauri-plugin-thermal-printer";

// Mixed Latin + Chinese content
const options = {
  code_page: 0,
  encode: ENCODE.WINDOWS_1252,
  use_gbk: true, // Chinese characters not in Win-1252 will be retried with GBK
};

Practical Examples

import { ENCODE, type CodePage } from "tauri-plugin-thermal-printer";

// Works on virtually all thermal printers.
// Accented characters are transliterated to ASCII.
const options: CodePage = {
  code_page: 0,
  encode: ENCODE.ACCENT_REMOVER,
};

Encoding in the Print Pipeline

The CodePage you set in options is passed to a TextEncoder instance at the start of every print job. This encoder is used for all text-bearing sections: Title, Subtitle, Text, and Table. The code_page value determines which ESC t n command is prepended to the document bytes, while encode and use_gbk control character-by-character text conversion.
// Simplified excerpt from src/process/process_print.rs
document.extend(PrinterControl::initialize()); // ESC @ — reset printer
document.extend(print_job.options.escpos_command()); // ESC t n — select code page
The TextEncoder is then shared across all text sections processed in the same job, ensuring consistent encoding throughout the entire document.

Build docs developers (and LLMs) love