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.

The TypeScript package exposes three async functions that communicate with the Rust backend via Tauri’s IPC layer. Each function invokes a named command on the plugin:thermal-printer channel and returns a Promise that resolves on success or throws a descriptive string on failure. All three functions must be called from the Tauri frontend context.
async function print_thermal_printer(printJobRequest: PrintJobRequest): Promise<void>
Sends a fully-described print job to the specified thermal printer. The Rust backend converts the sections array into raw ESC/POS bytes and dispatches them to the printer via the operating-system print subsystem (CUPS on Linux/macOS, WinAPI on Windows, Bluetooth SPP on Android). IPC command: plugin:thermal-printer|print_thermal_printer

Parameters

printJobRequest
PrintJobRequest
required
The complete print job definition. See PrintJobRequest for the full field reference.

Returns

Promise<void> — resolves when the printer has accepted the job.

Throws

string — a descriptive error message when the job fails. Common messages include:
  • "Printer not specified"
  • "Barcode data cannot be empty"
  • "Barcode type 'EAN13' only accepts numeric digits"
  • "QR data length 5000 exceeds maximum 4296 for error correction level 'M'"
  • "Table row 2 has 2 cells but 3 columns declared"
  • "column_widths sum (45) must equal paper chars_per_line (48)"
  • "Image data cannot be empty"

Example

import {
  print_thermal_printer,
  ENCODE,
  title,
  text,
  line,
  barcode,
  feed,
  cut,
  TEXT_ALIGN,
  BARCODE_TYPE,
  type PrintJobRequest,
} from 'tauri-plugin-thermal-printer'

const job: PrintJobRequest = {
  printer: 'TM-T20II',
  paper_size: 'Mm80',
  options: {
    code_page: 6,
    encode: ENCODE.WINDOWS_1252,
    use_gbk: false,
  },
  sections: [
    title('My Business'),
    text('Thank you for your purchase!', { align: TEXT_ALIGN.CENTER }),
    line('='),
    barcode('123456789012', BARCODE_TYPE.EAN13),
    feed(3),
    cut(),
  ],
}

try {
  await print_thermal_printer(job)
  console.log('Print job sent successfully')
} catch (error) {
  // error is a string, e.g. "Printer not found"
  console.error('Print failed:', error)
}

list_thermal_printers

async function list_thermal_printers(): Promise<PrinterInfo[]>
Queries the operating system for all configured printers and returns their metadata. On Linux and macOS this calls lpstat; on Windows it uses EnumPrintersW via WinAPI. IPC command: plugin:thermal-printer|list_thermal_printers

Parameters

This function takes no parameters.

Returns

Promise<PrinterInfo[]> — resolves with an array of printer descriptor objects.
PrinterInfo[]
array
Each element is a PrinterInfo object with the following fields:

Throws

string — an error message when enumeration fails (e.g. CUPS is not available on the system).

Example

import { list_thermal_printers } from 'tauri-plugin-thermal-printer'

try {
  const printers = await list_thermal_printers()

  // Example response:
  // [
  //   { name: "TM-T20II",        interface_type: "USB",     identifier: "usb://EPSON/TM-T20II",  status: "IDLE" },
  //   { name: "Star TSP143III",  interface_type: "NETWORK", identifier: "192.168.1.100:9100",    status: "IDLE" }
  // ]

  if (printers.length === 0) {
    console.warn('No printers found')
  } else {
    printers.forEach(p => {
      console.log(`${p.name} [${p.interface_type}] — ${p.status}`)
    })
  }
} catch (error) {
  console.error('Could not list printers:', error)
}

test_thermal_printer

async function test_thermal_printer(testPrintRequest: TestPrintRequest): Promise<void>
Sends a structured test job to a printer so you can verify each capability (text styles, barcodes, QR codes, images, feeds, beep, cash drawer, etc.) without writing a full print job by hand. Every test section is opt-in; set only the flags you need. IPC command: plugin:thermal-printer|test_thermal_printer

Parameters

testPrintRequest
TestPrintRequest
required
Full test configuration object. printer_info is required; all test flags are optional and default to false unless noted otherwise.

Returns

Promise<void> — resolves when the test print job has been accepted by the printer.

Throws

string — a descriptive error message if the test job fails (e.g. printer unreachable, invalid image data).

Example

import {
  test_thermal_printer,
  ENCODE,
  type TestPrintRequest,
} from 'tauri-plugin-thermal-printer'

const request: TestPrintRequest = {
  printer_info: {
    printer: 'TM-T20II',
    paper_size: 'Mm80',
    options: {
      code_page: 6,
      encode: ENCODE.WINDOWS_1252,
      use_gbk: false,
    },
    sections: [], // ignored by the backend during test mode
  },
  include_text: true,
  include_text_styles: true,
  include_alignment: true,
  include_columns: true,
  include_separators: true,
  include_barcode: true,
  include_barcode_types: false,
  include_qr: true,
  include_image: false,
  image_base64: null,
  include_beep: true,
  test_cash_drawer: false,
  cut_paper: true,
  test_feed: true,
  test_all_fonts: false,
  test_invert: false,
  test_rotate: false,
}

try {
  await test_thermal_printer(request)
  console.log('Test print completed')
} catch (error) {
  console.error('Test print failed:', error)
}
The sections array inside printer_info is not used during a test print. The backend generates all test content automatically from the flags you enable.

Build docs developers (and LLMs) love