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.

Media sections let you embed visual content in a print job. The Image section renders any base64-encoded raster image, automatically converting it to the monochrome bitmap format required by thermal printers. The Logo section recalls a pre-programmed graphic stored directly in the printer’s non-volatile (NV) memory, printing it instantly without transferring pixel data at runtime.

Image

The Image section accepts a base64-encoded image, resizes it to fit the specified max_width, converts it to monochrome, and sends the resulting bitmap to the printer. Color and grayscale images are automatically reduced to black-and-white — optionally using Floyd-Steinberg dithering for significantly improved tone reproduction.
data
string
required
Base64-encoded image data. Both plain base64 strings and data URIs (e.g. data:image/png;base64,...) are accepted. Must not be empty.
max_width
number
required
Maximum rendering width in pixels. 0 uses the full paper width automatically. Values larger than the paper width are clamped to the paper width — no manual calculation required.
align
"left" | "center" | "right"
required
Horizontal alignment of the image on the paper.
dithering
boolean
required
Apply Floyd-Steinberg dithering before sending to the printer. Recommended true for photographs and gradients; may be set to false for sharp black-and-white graphics (logos, icons) that do not benefit from dithering.
size
"normal" | "double_width" | "double_height" | "quadruple"
required
Output size multiplier applied after rendering. "quadruple" doubles both width and height.

Floyd-Steinberg dithering

Thermal printers can only print black or white dots — there are no gray levels. Floyd-Steinberg dithering converts a color or grayscale image to pure monochrome by distributing the quantization error of each pixel to its neighbors, creating the visual illusion of continuous tones through patterns of black and white dots. This is especially beneficial for photographs and images with gradients; for binary logos or icons already in black and white, dithering has little effect and may be disabled.

Paper width reference

Paper sizePixel widthNotes
Mm40256 pxHandheld ticket printers
Mm44288 pxCompact POS
Mm58384 pxCommon portable format
Mm72512 pxMid-range
Mm80576 pxStandard large format (default)
Mm104752 pxWide format
{
  "Image": {
    "data": "<BASE64_IMAGE_STRING>",
    "max_width": 0,
    "align": "center",
    "dithering": true,
    "size": "normal"
  }
}
max_width: 0 automatically uses the full printable width of the selected paper size. You do not need to look up the pixel width manually — just pass 0 and the plugin resolves it from paper_size.
Preparing images for best results:
  • Resize the image to match the paper width (e.g. 576 px wide for Mm80) before encoding.
  • Convert to PNG or JPEG before base64-encoding.
  • Keep image height reasonable — very tall images take longer to transfer and print.
  • For logos with clean edges, set dithering: false to avoid speckled borders.
data must not be empty. An empty string causes the backend to throw: "Image data cannot be empty".

The Logo section instructs the printer to recall and print a graphic stored in its NV (non-volatile) memory by key code. NV logos are pre-programmed into the printer firmware using the printer’s own configuration utility or setup software — they are not transmitted during the print job. This makes logo printing nearly instantaneous with no data transfer overhead.
key_code
number
required
The NV memory key index (1–255) that identifies the pre-stored logo.
mode
"normal" | "double_width" | "double_height" | "quadruple"
required
Output size multiplier for the recalled logo image.
{
  "Logo": {
    "key_code": 1,
    "mode": "normal"
  }
}
The logo must be pre-programmed into the printer’s NV memory before use. How you store logos varies by printer model and manufacturer — consult your printer’s manual or utilities (e.g. Epson TM-Utility for Epson printers). If no logo is stored at the given key_code, the printer typically prints nothing or a blank space.
Use the Logo section for header graphics on high-volume receipt printers where re-sending the full bitmap on every job would slow throughput. Store the logo once and recall it by key code for zero-overhead branded headers.

Complete example

import {
  print_thermal_printer,
  type PrintJobRequest,
  image, logo, title, text, line, feed, cut,
  IMAGE_MODE, TEXT_ALIGN, ENCODE,
} from "tauri-plugin-thermal-printer";

// Helper: load and base64-encode an image file (Node / Tauri context)
// const imageBase64 = readFileSync("logo.png").toString("base64");

const job: PrintJobRequest = {
  printer: "TM-T20II",
  paper_size: "Mm80",
  options: { code_page: 0, encode: ENCODE.ACCENT_REMOVER },
  sections: [
    // Option A: NV memory logo (fastest, no data transfer)
    logo(1, IMAGE_MODE.NORMAL),

    // Option B: Inline base64 image (flexible, any image)
    image("<BASE64_IMAGE_STRING>", {
      max_width: 0,             // full paper width (576 px for Mm80)
      align: TEXT_ALIGN.CENTER,
      dithering: true,          // recommended for photos/gradients
      size: IMAGE_MODE.NORMAL,
    }),

    line("="),
    title("ORDER CONFIRMATION"),
    text("Thank you for your purchase!"),
    feed(3),
    cut(),
  ],
};

try {
  await print_thermal_printer(job);
} catch (error) {
  // error is a string, e.g.: "Image data cannot be empty"
  console.error("Print failed:", error);
}

Build docs developers (and LLMs) love