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.

Every type described here is exported from tauri-plugin-thermal-printer and can be imported directly. Interfaces describe the shape of objects you pass to or receive from the three main functions; the PrintSections union type is the building block of every print job’s sections array.

PrintJobRequest

The top-level object passed to print_thermal_printer. It describes the target printer, the paper size, the encoding options, and the ordered list of sections to render.
interface PrintJobRequest {
  printer: string
  sections: PrintSections[]
  options: CodePage
  paper_size: PaperSize
}
printer
string
required
Name of the printer as registered with the OS (e.g. "TM-T20II"). On Android, supply the Bluetooth MAC address (e.g. "AA:BB:CC:DD:EE:FF").
sections
PrintSections[]
required
Ordered array of content sections. See PrintSections for all supported variants.
options
CodePage
required
ESC/POS code page selection and host-side encoding strategy. See CodePage.
paper_size
PaperSize
required
Roll width. See PaperSize for available values and their character/pixel metrics. Use DEFAULT_PAPER_SIZE ('Mm80') when in doubt.

PrinterInfo

Returned as elements of the array from list_thermal_printers.
interface PrinterInfo {
  name: string
  interface_type: string
  identifier: string
  status: string
}
name
string
Human-readable printer name as registered with the OS (e.g. "TM-T20II").
interface_type
string
Connection interface type (e.g. "USB", "NETWORK", "BLUETOOTH").
identifier
string
Unique device identifier such as a USB URI or "IP:PORT" string (e.g. "192.168.1.100:9100").
status
string
Current printer status (e.g. "IDLE", "BUSY").

CodePage

Controls two independent concerns: the ESC/POS code-page command sent to the printer (ESC t n) and the host-side character encoding applied before bytes are transmitted.
interface CodePage {
  code_page: number
  encode?: Encode
  use_gbk?: boolean
}
code_page
number
required
Raw value for the ESC t n command. Each printer model maps its own page numbers; consult your printer’s programming manual.
encode
Encode
default:"ACCENT_REMOVER"
Host-side encoding applied to all text sections. ENCODE.ACCENT_REMOVER transliterates accented characters to plain ASCII before transmission (á → a, ß → ss, € → EUR). All other values come from encoding_rs statics. See ENCODE.
use_gbk
boolean
default:"false"
When true, characters that the selected encode cannot represent are retried with GBK before falling back to raw UTF-8 bytes.

GlobalStyles

Optional style overrides applied to a text section. When used as a PrintSections variant ({ GlobalStyles: ... }), the styles become the default for all subsequent text sections until changed again.
interface GlobalStyles {
  bold?: boolean
  underline?: boolean
  align?: TextAlign
  italic?: boolean
  invert?: boolean
  font?: TextFont
  rotate?: boolean
  upside_down?: boolean
  size?: TextSize
}
bold
boolean
Bold text.
underline
boolean
Underlined text.
align
TextAlign
Horizontal alignment — 'left' | 'center' | 'right'.
italic
boolean
Italic text (hardware support varies by printer model).
invert
boolean
White text on a black background.
font
TextFont
Printer font — 'A' | 'B' | 'C'.
rotate
boolean
Rotate text 90 degrees clockwise.
upside_down
boolean
Print text upside down.
size
TextSize
Character size — 'normal' | 'height' | 'width' | 'double'.

PaperSize

String literal union that identifies the roll width. Use DEFAULT_PAPER_SIZE ('Mm80') when in doubt.
type PaperSize =
  | 'Mm40'
  | 'Mm44'
  | 'Mm58'
  | 'Mm72'
  | 'Mm80'
  | 'Mm104'
ValuePaper WidthChars / LinePixels WidthTypical Use
'Mm40'40 mm21256Handheld ticket printers
'Mm44'44 mm24288Compact POS
'Mm58'58 mm32384Small format, portable
'Mm72'72 mm42512Mid-range printers
'Mm80'80 mm48576Standard large format (default)
'Mm104'104 mm62752Wide format

PrintSections

A discriminated union of all 16 printable section variants. Every element of the sections array in PrintJobRequest must be one of these shapes.
type PrintSections =
  | { Title: Title }
  | { Subtitle: Subtitle }
  | { Text: Text }
  | { Feed: Feed }
  | { Cut: Cut }
  | { Beep: Beep }
  | { Drawer: Drawer }
  | { GlobalStyles: GlobalStyles }
  | { Qr: Qr }
  | { Barcode: Barcode }
  | { Table: Table }
  | { DataMatrix: DataMatrixModel }
  | { Pdf417: Pdf417 }
  | { Image: Image }
  | { Logo: Logo }
  | { Line: Line }
Use the builder helperstitle(), text(), qr(), etc. — to construct these objects without writing the wrapper key by hand.

TestPrintRequest

Passed to test_thermal_printer. All fields except printer_info are optional.
interface TestPrintRequest {
  printer_info: PrintJobRequest
  include_text?: boolean
  include_custom_text?: boolean
  custom_text?: string | null
  include_text_styles?: boolean
  include_alignment?: boolean
  include_columns?: boolean
  include_separators?: boolean
  include_barcode?: boolean
  include_barcode_types?: boolean
  include_qr?: boolean
  include_image?: boolean
  image_base64?: string | null
  include_beep?: boolean
  test_cash_drawer?: boolean
  cut_paper?: boolean
  test_feed?: boolean
  test_all_fonts?: boolean
  test_invert?: boolean
  test_rotate?: boolean
}
printer_info
PrintJobRequest
required
Printer configuration. The sections array is ignored — the backend generates all test content from the flags below.
include_text
boolean
default:"false"
Print a basic text sample.
include_custom_text
boolean
default:"false"
Print the string in custom_text.
custom_text
string | null
default:"null"
Custom text printed when include_custom_text is true.
include_text_styles
boolean
default:"false"
Print bold, underline, and inverted style samples.
include_alignment
boolean
default:"false"
Print left, center, and right alignment samples.
include_columns
boolean
default:"false"
Print a multi-column table sample.
include_separators
boolean
default:"false"
Print horizontal separator line samples.
include_barcode
boolean
default:"false"
Print a CODE128 barcode sample.
include_barcode_types
boolean
default:"false"
Print one sample for each supported barcode type.
include_qr
boolean
default:"false"
Print a QR code sample.
include_image
boolean
default:"false"
Print the image provided in image_base64.
image_base64
string | null
default:"null"
Base64-encoded image used when include_image is true.
include_beep
boolean
default:"false"
Emit an audible beep.
test_cash_drawer
boolean
default:"false"
Open the cash drawer.
cut_paper
boolean
default:"false"
Cut the paper at the end of the test.
test_feed
boolean
default:"false"
Run a paper-feed test.
test_all_fonts
boolean
default:"false"
Print a sample in every available font (A, B, C).
test_invert
boolean
default:"false"
Print an inverted-text sample.
test_rotate
boolean
default:"false"
Print a 90°-rotated text sample.

Section Interfaces

Each variant of PrintSections wraps one of the following interfaces.

Title

Prints text with forced double size and center alignment.
interface Title {
  text: string
  styles?: GlobalStyles
}
text
string
required
Text to print.
styles
GlobalStyles
Optional style overrides. Defaults force double size and center alignment.

Subtitle

Prints text with forced bold and increased height.
interface Subtitle {
  text: string
  styles?: GlobalStyles
}
text
string
required
Text to print.
styles
GlobalStyles
Optional style overrides. Defaults force bold and height size.

Text

Prints body text with fully optional styles.
interface Text {
  text: string
  styles?: GlobalStyles
}
text
string
required
Text to print.
styles
GlobalStyles
Optional style overrides. Inherits current global styles when omitted.

Feed

Advances the paper.
interface Feed {
  feed_type: FeedType
  value: number
}
feed_type
FeedType
required
'lines' — advance N lines (ESC d n); 'dots' — advance N dot rows (ESC J n); 'line_feed' — send N raw LF characters.
value
number
required
Amount to advance.

Cut

Cuts the paper.
interface Cut {
  mode: CutMode
  feed: number
}
mode
CutMode
required
'full', 'partial', 'partial_alt', or 'partial_alt2'. See CutMode.
feed
number
required
Lines to advance before cutting.

Beep

Emits an audible beep via the printer’s buzzer.
interface Beep {
  times: number
  duration: number
}
times
number
required
Number of beeps (1–9).
duration
number
required
Duration per beep in milliseconds (1–255).

Drawer

Opens the cash drawer.
interface Drawer {
  pin: 2 | 5
  pulse_time: number
}
pin
2 | 5
required
Drawer kick pin number.
pulse_time
number
required
Kick pulse duration in milliseconds.

Table

Prints a columnar table. Column widths must sum to the paper’s chars_per_line when provided.
interface Table {
  columns: number
  column_widths?: number[]
  header?: Text[]
  body: Text[][]
  truncate: boolean
}
columns
number
required
Number of columns.
column_widths
number[]
Per-column widths in characters. Length must equal columns and the sum must equal the paper’s chars/line (e.g. 48 for Mm80). Evenly distributed when omitted.
header
Text[]
Optional column header cells — must have exactly columns elements.
body
Text[][]
required
Data rows — each row must have exactly columns cells.
truncate
boolean
required
When true, cell text that exceeds its column width is truncated. When false, long text wraps.

Qr

Prints a QR code.
interface Qr {
  data: string
  size: number
  error_correction: QrErrorCorrection
  model: 1 | 2
  align?: TextAlign
}
data
string
required
QR payload. Must not be empty. Max length depends on error-correction level.
size
number
required
Module size 1–16 (recommended 5–6).
error_correction
QrErrorCorrection
required
'L' (7%, 7089 chars max) | 'M' (15%, 4296 chars) | 'Q' (25%, 2953 chars) | 'H' (30%, 1817 chars).
model
1 | 2
required
QR model. Model 2 is recommended.
align
TextAlign
Horizontal alignment. Defaults to current global alignment.

Barcode

Prints a 1-D barcode.
interface Barcode {
  data: string
  barcode_type: BarcodeType
  width: number
  height: number
  text_position: BarcodeTextPosition
  align?: TextAlign
}
data
string
required
Barcode payload. Must not be empty. Numeric-only types (UPC-A, UPC-E, EAN13, EAN8, ITF) accept only digit characters.
barcode_type
BarcodeType
required
One of: 'UPC-A' | 'UPC-E' | 'EAN13' | 'EAN8' | 'CODE39' | 'ITF' | 'CODABAR' | 'CODE93' | 'CODE128'.
width
number
required
Bar module width 2–6.
height
number
required
Bar height in dots (must be greater than 0).
text_position
BarcodeTextPosition
required
'none' | 'above' | 'below' | 'both'.
align
TextAlign
Horizontal alignment. Defaults to current global alignment.

DataMatrixModel

Prints a DataMatrix 2-D code.
interface DataMatrixModel {
  data: string
  size: number
}
data
string
required
DataMatrix payload.
size
number
required
Module size 1–16.

Pdf417

Prints a PDF417 stacked barcode.
interface Pdf417 {
  data: string
  columns: number
  rows: number
  width: number
  height: number
  error_correction: number
}
data
string
required
PDF417 payload.
columns
number
required
0 for auto, or 1–30 data columns.
rows
number
required
0 for auto, or 3–90 data rows.
width
number
required
Module width 2–8.
height
number
required
Row height 2–8.
error_correction
number
required
Error correction level 0–8.

Image

Prints a raster image. Base64 strings with or without a data: URI prefix are both accepted.
interface Image {
  data: string
  max_width: number
  align: TextAlign
  dithering: boolean
  size: ImageMode
}
data
string
required
Base64-encoded image. Must not be empty.
max_width
number
required
Maximum output width in pixels. 0 (or values larger than the paper width) are automatically clamped to the paper width.
align
TextAlign
required
Horizontal alignment: 'left' | 'center' | 'right'.
dithering
boolean
required
Apply Floyd-Steinberg dithering for better quality on monochrome printers.
size
ImageMode
required
Print scale — 'normal' | 'double_width' | 'double_height' | 'quadruple'.

Prints a logo image previously stored in the printer’s NV memory.
interface Logo {
  key_code: number
  mode: ImageMode
}
key_code
number
required
NV memory key code (1–255).
mode
ImageMode
required
Print scale — 'normal' | 'double_width' | 'double_height' | 'quadruple'.

Line

Prints a full-width horizontal separator by repeating a single character across the paper.
interface Line {
  character: string
}
character
string
required
The character to repeat (e.g. '-', '=', '_'). Must be a single character.

Primitive Type Aliases

These string-literal unions are used throughout the interfaces above and are exported as both types and constant objects.
TypeValues
TextAlign'left' | 'center' | 'right'
TextSize'normal' | 'height' | 'width' | 'double'
TextFont'A' | 'B' | 'C'
BarcodeType'UPC-A' | 'UPC-E' | 'EAN13' | 'EAN8' | 'CODE39' | 'ITF' | 'CODABAR' | 'CODE93' | 'CODE128'
BarcodeTextPosition'none' | 'above' | 'below' | 'both'
QrErrorCorrection'L' | 'M' | 'Q' | 'H'
ImageMode'normal' | 'double_width' | 'double_height' | 'quadruple'
FeedType'lines' | 'dots' | 'line_feed'
CutMode'full' | 'partial' | 'partial_alt' | 'partial_alt2'
EncodeAll values of the ENCODE constant object (e.g. 'BIG5', 'WINDOWS_1252', 'ACCENT_REMOVER')

Build docs developers (and LLMs) love