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.

Text sections are the backbone of most thermal printer receipts and tickets. They cover everything from bold store headings and item tables to simple separator lines, and a GlobalStyles section lets you set formatting defaults that cascade across all subsequent text output without repeating yourself on every line.

Title

The Title section prints a line of text with forced double size and center alignment, making it ideal for store names, receipt headers, or any top-level heading. You may pass optional styles to override color inversion, font, or other properties, but the double size and center alignment are always applied on top.
text
string
required
The heading text to print.
styles
GlobalStyles
Optional style overrides applied on top of the forced defaults. See GlobalStyles for all fields.
{
  "Title": {
    "text": "MY STORE"
  }
}
Double size and center alignment are always enforced for Title sections regardless of what you pass in styles. To print a heading without these forced styles, use a Text section with explicit size and align values instead.

Subtitle

The Subtitle section prints a line with forced bold and increased height (taller characters without doubling the width). Use it for secondary headings, branch names, receipt sub-headers, or any text that needs more visual weight than plain Text but less dominance than Title.
text
string
required
The subtitle text to print.
styles
GlobalStyles
Optional style overrides. Bold and height size are always enforced on top.
{
  "Subtitle": {
    "text": "Downtown Branch"
  }
}

Text

The Text section prints a single line (or wrapped block) of content using the current global styles as defaults. Any fields you include in styles override the corresponding global default — you only need to specify what you want to change. Omitting styles entirely inherits whatever GlobalStyles was last set.
text
string
required
The text content to print.
styles
GlobalStyles
Partial or full style object. Only the fields you set override the current global defaults.
{
  "Text": {
    "text": "Thank you for your purchase!"
  }
}
You only need to specify the style fields you actually want to change. For example, { "bold": true } keeps all other properties at their current global defaults — you do not have to repeat "underline": false or "align": "left" if they are already set.

Table

The Table section renders a multi-column grid. Columns can have custom widths and each cell supports the same text + styles structure as a Text section. Tables are perfect for item lists, price breakdowns, and any aligned columnar data on a receipt.
columns
number
required
Number of columns in the table (e.g. 3).
body
Text[][]
required
Array of rows. Each row is an array of { text, styles? } cell objects. Every row must contain exactly columns cells.
column_widths
number[]
Array of character widths for each column. When provided:
  • Length must equal columns.
  • The sum must equal the paper’s chars-per-line (e.g. 48 for Mm80, 32 for Mm58).
  • If omitted, columns are distributed evenly across the paper width.
header
Text[]
Optional array of header cells. Must contain exactly columns elements if provided.
truncate
boolean
required
When true, long cell text is truncated to fit its column width. When false, text wraps onto the next line. The table() builder defaults to true.
{
  "Table": {
    "columns": 3,
    "body": [
      [
        { "text": "1" },
        { "text": "Americano" },
        { "text": "$2.50" }
      ]
    ],
    "truncate": false
  }
}
Row cell count must match columns exactly. If a row has fewer or more cells than the declared columns value, the Rust backend will throw an error: "Table row N has X cells but Y columns declared".
column_widths sum must match chars_per_line. When column_widths is provided and its sum does not equal the paper’s chars-per-line, printing will fail with: "column_widths sum (N) must equal paper chars_per_line (M)". Use the table below to check your paper size’s character width.

Paper width reference

Paper sizeChars per lineNotes
Mm4021Handheld ticket printers
Mm4424Compact POS
Mm5832Common portable format
Mm7242Mid-range
Mm8048Standard large format (default)
Mm10462Wide format

Line

The Line section fills the entire paper width with a repeated single character, creating a horizontal separator. It is one of the most commonly used sections on receipts — separating the header from the item list, and the total from the payment section.
character
string
required
The single character to repeat across the full paper width. Common choices: "-", "=", "_", "*", "~".
{ "Line": { "character": "-" } }

GlobalStyles

The GlobalStyles section changes the default styles for all subsequent text sections (Title, Subtitle, Text, Table, Line) until another GlobalStyles section overrides them again. All fields are optional — you only need to specify what you want to change.
bold
boolean
Enable bold text. Default: false.
underline
boolean
Enable underlined text. Default: false.
align
"left" | "center" | "right"
Text alignment. Default: "left".
italic
boolean
Enable italic text. Default: false.
invert
boolean
Invert colors (white text on black background). Default: false.
font
"A" | "B" | "C"
Select printer font. Font A is the widest and most readable; Font B is narrower. Default: "A".
rotate
boolean
Rotate text 90 degrees clockwise. Default: false.
upside_down
boolean
Print text upside-down. Default: false.
size
"normal" | "height" | "width" | "double"
Character size. "height" doubles height only, "width" doubles width only, "double" doubles both. Default: "normal".
{
  "GlobalStyles": {
    "align": "center"
  }
}
GlobalStyles affects all subsequent sections in the sections array. It does not retroactively change sections that have already been processed. Insert a second GlobalStyles section to revert any changes for later sections.

Complete example

The example below combines all text section types into a short receipt for an 80 mm printer.
import {
  print_thermal_printer,
  type PrintJobRequest,
  title, subtitle, text, line, table, globalStyles, feed, cut,
  TEXT_ALIGN, TEXT_SIZE, ENCODE,
} from "tauri-plugin-thermal-printer";

const job: PrintJobRequest = {
  printer: "TM-T20II",
  paper_size: "Mm80",
  options: { code_page: 0, encode: ENCODE.ACCENT_REMOVER },
  sections: [
    // ── Header ──────────────────────────────────────────────
    globalStyles({ align: TEXT_ALIGN.CENTER }),
    title("DEMO CAFÉ"),
    subtitle("Receipt #00142"),
    text("123 Main St — (555) 000-1234"),
    line("="),

    // ── Item table ───────────────────────────────────────────
    globalStyles({ align: TEXT_ALIGN.LEFT }),
    table(
      3,
      [
        [text("1"), text("Espresso"),   text("$3.00", { align: TEXT_ALIGN.RIGHT })],
        [text("2"), text("Croissant"),  text("$7.50", { align: TEXT_ALIGN.RIGHT })],
        [text("1"), text("Cold Brew"),  text("$4.25", { align: TEXT_ALIGN.RIGHT })],
      ],
      {
        column_widths: [4, 30, 14], // 4+30+14 = 48 (Mm80)
        header: [
          text("QTY",   { bold: true }),
          text("ITEM",  { bold: true }),
          text("PRICE", { bold: true, align: TEXT_ALIGN.RIGHT }),
        ],
        truncate: true,
      }
    ),
    line("-"),

    // ── Totals ───────────────────────────────────────────────
    text("Total: $14.75", { bold: true, size: TEXT_SIZE.DOUBLE, align: TEXT_ALIGN.RIGHT }),
    line("="),

    // ── Footer ───────────────────────────────────────────────
    globalStyles({ align: TEXT_ALIGN.CENTER }),
    text("Thank you for visiting!"),
    text("www.democafe.com"),

    feed(3),
    cut(),
  ],
};

await print_thermal_printer(job);

Build docs developers (and LLMs) love