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 element in a PrintJobRequest.sections array must be a PrintSections discriminated union object — { Title: { text: '...' } }, { Cut: { mode: 'partial', feed: 4 } }, and so on. The builder helpers exported by tauri-plugin-thermal-printer create these wrapper objects for you, with sensible defaults pre-applied, so you can write readable, concise section arrays without repeating the union key on every line. Each builder always returns a PrintSections value and can be used directly inside a sections array or composed into variables.

title

function title(text: string, styles?: GlobalStyles): PrintSections
Creates a { Title: { text, styles } } section. The backend renders titles with forced double size and center alignment unless overridden in styles.
text
string
required
Title text to print.
styles
GlobalStyles
Optional style overrides applied on top of the title defaults.
import { title } from 'tauri-plugin-thermal-printer'

title('MY BUSINESS')
title('MY BUSINESS', { align: 'left', bold: true })

subtitle

function subtitle(text: string, styles?: GlobalStyles): PrintSections
Creates a { Subtitle: { text, styles } } section. The backend renders subtitles with forced bold and height size unless overridden.
text
string
required
Subtitle text to print.
styles
GlobalStyles
Optional style overrides applied on top of the subtitle defaults.
import { subtitle } from 'tauri-plugin-thermal-printer'

subtitle('Receipt #001')
subtitle('Receipt #001', { align: 'center' })

text

function text(text: string, styles?: GlobalStyles): PrintSections
Creates a { Text: { text, styles } } section for general body text. Inherits the current global styles when styles is omitted.
text
string
required
Body text to print.
styles
GlobalStyles
Optional per-section style overrides.
import { text, TEXT_ALIGN, TEXT_SIZE } from 'tauri-plugin-thermal-printer'

text('Normal line')
text('Bold right-aligned total', { bold: true, align: TEXT_ALIGN.RIGHT })
text('Grand total: $9.50',       { bold: true, size: TEXT_SIZE.DOUBLE })

line

function line(character: string = '-'): PrintSections
Creates a { Line: { character } } section that repeats character across the full paper width.
character
string
default:"'-'"
Single character to repeat (e.g. '-', '=', '_', '*').
import { line } from 'tauri-plugin-thermal-printer'

line()      // uses '-'
line('=')
line('*')

feed

function feed(value: number, feed_type: FeedType = 'lines'): PrintSections
Creates a { Feed: { feed_type, value } } section that advances the paper.
value
number
required
Amount to advance. Unit depends on feed_type.
feed_type
FeedType
default:"'lines'"
'lines' — advance N lines (ESC d n); 'dots' — advance N dot rows (ESC J n); 'line_feed' — send N raw LF characters.
import { feed } from 'tauri-plugin-thermal-printer'

feed(3)               // advance 3 lines
feed(20, 'dots')      // advance 20 dot rows
feed(2, 'line_feed')  // 2 raw LF characters

cut

function cut(mode: CutMode = 'partial', feedLines: number = 4): PrintSections
Creates a { Cut: { mode, feed: feedLines } } section.
mode
CutMode
default:"'partial'"
'full' | 'partial' | 'partial_alt' | 'partial_alt2'.
feedLines
number
default:"4"
Lines to advance before cutting.
import { cut, CUT_MODE } from 'tauri-plugin-thermal-printer'

cut()                        // partial cut, 4 feed lines
cut(CUT_MODE.FULL, 5)        // full cut, 5 feed lines
cut('partial_alt', 0)        // alternate partial cut command, no feed

globalStyles

function globalStyles(styles: GlobalStyles): PrintSections
Creates a { GlobalStyles: styles } section. When the backend encounters this section it updates the running default styles applied to subsequent Title, Subtitle, Text, and Table sections.
styles
GlobalStyles
required
Style values to set as the new global default.
import { globalStyles, text, TEXT_ALIGN } from 'tauri-plugin-thermal-printer'

const sections = [
  globalStyles({ align: TEXT_ALIGN.LEFT, font: 'A' }),
  text('This line is left-aligned font A'),
  globalStyles({ align: TEXT_ALIGN.CENTER, bold: true }),
  text('This line is centered and bold'),
]

beep

function beep(times: number = 1, duration: number = 3): PrintSections
Creates a { Beep: { times, duration } } section that triggers the printer’s built-in buzzer.
times
number
default:"1"
Number of beeps (1–9).
duration
number
default:"3"
Duration per beep in milliseconds (1–255).
import { beep } from 'tauri-plugin-thermal-printer'

beep()          // 1 beep, 3 ms
beep(2, 100)    // 2 beeps, 100 ms each

drawer

function drawer(pin: 2 | 5 = 2, pulse_time: number = 120): PrintSections
Creates a { Drawer: { pin, pulse_time } } section that opens the cash drawer.
pin
2 | 5
default:"2"
Drawer kick pin. Most cash drawers use pin 2.
pulse_time
number
default:"120"
Kick pulse duration in milliseconds.
import { drawer } from 'tauri-plugin-thermal-printer'

drawer()          // pin 2, 120 ms
drawer(5, 200)    // pin 5, 200 ms

table

function table(
  columns: number,
  body: Text[][],
  options?: {
    column_widths?: number[]
    header?: Text[]
    truncate?: boolean
  },
): PrintSections
Creates a { Table: { ... } } section. The truncate option defaults to true when using the builder (the raw interface requires it to be set explicitly).
columns
number
required
Number of columns.
body
Text[][]
required
Data rows. Each inner array must have exactly columns elements.
options
object
import { table, text, TEXT_ALIGN } from 'tauri-plugin-thermal-printer'

table(
  3,
  [
    [text('1'), text('Americano'),  text('$2.50', { align: TEXT_ALIGN.RIGHT })],
    [text('2'), text('Croissant'),  text('$7.00', { align: TEXT_ALIGN.RIGHT })],
  ],
  {
    column_widths: [6, 28, 14],
    header: [
      text('QTY',   { bold: true }),
      text('ITEM',  { bold: true }),
      text('TOTAL', { bold: true, align: TEXT_ALIGN.RIGHT }),
    ],
    truncate: true,
  },
)

qr

function qr(
  data: string,
  options?: {
    size?: number
    error_correction?: QrErrorCorrection
    model?: 1 | 2
    align?: TextAlign
  },
): PrintSections
Creates a { Qr: { ... } } section.
data
string
required
QR payload. Must not be empty. Maximum length depends on error_correction.
options
object
import { qr, QR_ERROR_CORRECTION, TEXT_ALIGN } from 'tauri-plugin-thermal-printer'

qr('https://example.com')
qr('https://example.com/order/123', {
  size: 6,
  error_correction: QR_ERROR_CORRECTION.M,
  model: 2,
  align: TEXT_ALIGN.CENTER,
})

barcode

function barcode(
  data: string,
  barcode_type: BarcodeType = 'CODE128',
  options?: {
    width?: number
    height?: number
    text_position?: BarcodeTextPosition
    align?: TextAlign
  },
): PrintSections
Creates a { Barcode: { ... } } section.
data
string
required
Barcode payload. Must not be empty.
barcode_type
BarcodeType
default:"'CODE128'"
One of: 'UPC-A' | 'UPC-E' | 'EAN13' | 'EAN8' | 'CODE39' | 'ITF' | 'CODABAR' | 'CODE93' | 'CODE128'.
options
object
import {
  barcode,
  BARCODE_TYPE,
  BARCODE_TEXT_POSITION,
  TEXT_ALIGN,
} from 'tauri-plugin-thermal-printer'

barcode('123456789012')   // CODE128, default options

barcode('5901234123457', BARCODE_TYPE.EAN13, {
  width: 3,
  height: 70,
  text_position: BARCODE_TEXT_POSITION.BELOW,
  align: TEXT_ALIGN.CENTER,
})

dataMatrix

function dataMatrix(data: string, size: number = 6): PrintSections
Creates a { DataMatrix: { data, size } } section.
data
string
required
DataMatrix payload.
size
number
default:"6"
Module size 1–16.
import { dataMatrix } from 'tauri-plugin-thermal-printer'

dataMatrix('A-1001')
dataMatrix('A-1001', 8)

pdf417

function pdf417(
  data: string,
  options?: {
    columns?: number
    rows?: number
    width?: number
    height?: number
    error_correction?: number
  },
): PrintSections
Creates a { Pdf417: { ... } } section.
data
string
required
PDF417 payload.
options
object
import { pdf417 } from 'tauri-plugin-thermal-printer'

pdf417('A-1001|TOTAL=9.50|PAID')

pdf417('A-1001|TOTAL=9.50|PAID', {
  columns: 0,
  rows: 0,
  width: 2,
  height: 3,
  error_correction: 2,
})

image

function image(
  data: string,
  options?: {
    max_width?: number
    align?: TextAlign
    dithering?: boolean
    size?: ImageMode
  },
): PrintSections
Creates a { Image: { ... } } section. Base64 strings with or without a data: URI prefix are both accepted.
data
string
required
Base64-encoded image. Must not be empty.
options
object
import { image, IMAGE_MODE, TEXT_ALIGN } from 'tauri-plugin-thermal-printer'

image('<BASE64_STRING>')

image('<BASE64_STRING>', {
  max_width: 0,
  align: TEXT_ALIGN.CENTER,
  dithering: true,
  size: IMAGE_MODE.NORMAL,
})

function logo(key_code: number, mode: ImageMode = 'normal'): PrintSections
Creates a { Logo: { key_code, mode } } section that prints a logo previously stored in the printer’s NV memory.
key_code
number
required
NV memory key code (1–255).
mode
ImageMode
default:"'normal'"
Print scale — 'normal' | 'double_width' | 'double_height' | 'quadruple'.
import { logo, IMAGE_MODE } from 'tauri-plugin-thermal-printer'

logo(1)
logo(1, IMAGE_MODE.DOUBLE_WIDTH)

Complete Example

The example below uses every builder function in a single print job, mirroring the full builder example from the project README.
import {
  print_thermal_printer,
  type PrintJobRequest,
  title,
  subtitle,
  text,
  line,
  feed,
  cut,
  globalStyles,
  beep,
  drawer,
  table,
  qr,
  barcode,
  dataMatrix,
  pdf417,
  image,
  logo,
  ENCODE,
  TEXT_ALIGN,
  TEXT_SIZE,
  BARCODE_TYPE,
  BARCODE_TEXT_POSITION,
  QR_ERROR_CORRECTION,
  IMAGE_MODE,
} from 'tauri-plugin-thermal-printer'

const job: PrintJobRequest = {
  printer: 'TM-T20II',
  paper_size: 'Mm80',
  options: {
    code_page: 0,
    encode: ENCODE.ACCENT_REMOVER,
    use_gbk: false,
  },
  sections: [
    globalStyles({ align: TEXT_ALIGN.LEFT }),
    title('DEMO STORE'),
    subtitle('Receipt #A-1001'),
    text('Date: 2026-03-30 14:22'),
    line('='),
    table(
      3,
      [
        [text('1'), text('Americano'), text('$2.50', { align: TEXT_ALIGN.RIGHT })],
        [text('2'), text('Croissant'), text('$7.00', { align: TEXT_ALIGN.RIGHT })],
      ],
      {
        column_widths: [6, 28, 14],
        header: [
          text('QTY',   { bold: true }),
          text('ITEM',  { bold: true }),
          text('TOTAL', { bold: true, align: TEXT_ALIGN.RIGHT }),
        ],
        truncate: true,
      },
    ),
    line('-'),
    text('Grand total: $9.50', {
      bold: true,
      size: TEXT_SIZE.DOUBLE,
      align: TEXT_ALIGN.RIGHT,
    }),
    qr('https://example.com/r/A-1001', {
      size: 6,
      error_correction: QR_ERROR_CORRECTION.M,
      model: 2,
      align: TEXT_ALIGN.CENTER,
    }),
    barcode('123456789012', BARCODE_TYPE.EAN13, {
      width: 3,
      height: 70,
      text_position: BARCODE_TEXT_POSITION.BELOW,
      align: TEXT_ALIGN.CENTER,
    }),
    dataMatrix('A-1001', 6),
    pdf417('A-1001|TOTAL=9.50|PAID', {
      columns: 0,
      rows: 0,
      width: 2,
      height: 3,
      error_correction: 2,
    }),
    image('<BASE64_IMAGE>', {
      max_width: 0,
      align: TEXT_ALIGN.CENTER,
      dithering: true,
      size: IMAGE_MODE.NORMAL,
    }),
    logo(1, IMAGE_MODE.NORMAL),
    drawer(2, 120),
    beep(1, 3),
    feed(3),
    cut(),
  ],
}

await print_thermal_printer(job)

Build docs developers (and LLMs) love