### Alternative Installation via Git Clone Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Install the plugin by cloning the repository and building it locally, useful for development or specific versions. ```bash git clone https://github.com/luis3132/tauri-plugin-thermal-printer cd tauri-plugin-thermal-printer cargo build --release && bun i && bun run build ``` -------------------------------- ### Add tauri-plugin-thermal-printer to Bun/NPM/PNPM Project Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Install the thermal printer plugin for your JavaScript/TypeScript-based Tauri project using Bun, NPM, or PNPM. ```bash bun add tauri-plugin-thermal-printer ``` -------------------------------- ### Install Dependencies and Build JS/TS Artifacts Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/CONTRIBUTING.md If you modify JavaScript or TypeScript files, you need to install dependencies and rebuild the artifacts. Ensure you are in the repository root. ```bash bun install bun run build ``` -------------------------------- ### Comprehensive Print Job Example Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Illustrates a complete print job request using a wide array of section builders and configuration options. Ensure all necessary imports are included. ```typescript 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: { cut_paper: true, beep: false, open_cash_drawer: false, code_page: { code_page: 6, encode: ENCODE.WINDOWS_1252, 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("", { 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); ``` -------------------------------- ### Add tauri-plugin-thermal-printer to Rust Project Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Install the thermal printer plugin for your Rust-based Tauri project using Cargo. ```bash cargo add tauri-plugin-thermal-printer ``` -------------------------------- ### JSON Text Section Example Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Define a 'Text' section for a print job. This prints simple text with optional styles. Styles can be customized or omitted for defaults. ```json { "Text": { "text": "Normal text", "styles": { "bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal" } } } ``` ```json { "Text": { "text": "My Subtitle", "styles": { "bold": true, "underline": true } } } ``` ```json { "Text": { "text": "My Subtitle" } } ``` -------------------------------- ### JSON Feed Section Example Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Define a 'Feed' section to advance paper by a specific number of lines, dots, or raw LF characters. The `value` specifies the amount. ```json { "Feed": { "feed_type": "lines", "value": 3 } } ``` -------------------------------- ### Error Handling Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Guidance on how to handle errors thrown by the thermal printer plugin functions, including examples for print and list operations. ```APIDOC ## Error Handling `print_thermal_printer` and `test_thermal_printer` now return `Promise` and **throw** a descriptive `string` when something fails. Always wrap calls in `try/catch`: ```typescript import { print_thermal_printer, type PrintJobRequest } from "tauri-plugin-thermal-printer"; try { await print_thermal_printer(job); } catch (error) { // `error` is a string describing what went wrong, e.g.: // "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" console.error("Print failed:", error); } ``` `list_thermal_printers` also throws on failure (e.g., CUPS not available): ```typescript try { const printers = await list_thermal_printers(); } catch (error) { console.error("Could not list printers:", error); } ``` ``` -------------------------------- ### Example Print Job Request JSON Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md This JSON structure defines a print job, including printer selection, paper size, options like cutting and beeping, and an array of sections to be printed. ```json { "printer": "TM-T20II", "paper_size": "Mm80", "options": { "cut_paper": true, "beep": false }, "sections": [ {"Title": {"text": "My Title"}}, {"Text": {"text": "Normal content"}}, {"Table": {"columns": 3, "body": [["A", "B", "C"]]}} ] } ``` -------------------------------- ### Build Basic Print Sections Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Demonstrates using various section builder helpers to construct a list of sections for a thermal print job. Imports are required for all used helpers. ```typescript import { title, subtitle, text, line, feed, cut, globalStyles, beep, drawer, table, qr, barcode, dataMatrix, pdf417, image, logo, TEXT_ALIGN, TEXT_SIZE, BARCODE_TYPE, QR_ERROR_CORRECTION, } from "tauri-plugin-thermal-printer"; const sections = [ title("My Business"), subtitle("Receipt #001"), text("Thank you for your purchase!", { align: TEXT_ALIGN.CENTER }), line("="), qr("https://example.com/order/123", { size: 6, error_correction: QR_ERROR_CORRECTION.M, }), barcode("123456789012", BARCODE_TYPE.EAN13), beep(), text("Total: $50.00", { bold: true, size: TEXT_SIZE.DOUBLE }), line("-"), feed(3), cut(), ]; ``` -------------------------------- ### Verify Rust Builds Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/CONTRIBUTING.md Run this command to ensure your Rust code changes build correctly. This is a required step before submitting a pull request. ```bash cargo build --release ``` -------------------------------- ### Qr Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Prints a QR code with specified data and formatting options. ```APIDOC ## Qr ### Description Prints a QR code with specified data and formatting options. ### Method (Not specified, assumed to be part of a larger command) ### Endpoint (Not specified) ### Parameters #### Request Body - **data** (string) - Required - QR data. Must not be empty. Maximum length depends on error correction level. - **size** (number) - Required - Module size (1–16) - **error_correction** (string) - Required - Error correction level: `"L"` (7089 chars max), `"M"` (4296, default), `"Q"` (2953), `"H"` (1817) - **model** (number) - Required - QR model (1 or 2) - **align** (string) - Optional - Alignment: `"left"`, `"center"`, `"right"` ### Request Example ```json { "Qr": { "data": "https://example.com", "size": 5, "error_correction": "M", "model": 2, "align": "center" } } ``` ### Response (Not specified) ``` -------------------------------- ### TypeScript Error Handling for Listing Printers Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Handle errors when listing available printers using `list_thermal_printers`. This function can throw an error if, for example, CUPS is not available. ```typescript try { const printers = await list_thermal_printers(); } catch (error) { console.error("Could not list printers:", error); } ``` -------------------------------- ### Initialize Thermal Printer Plugin in Tauri Source: https://context7.com/luis3132/tauri-plugin-thermal-printer/llms.txt Integrates the thermal printer plugin into a Tauri application. This involves adding the plugin to the app builder and ensuring necessary permissions are configured in `default.json`. ```rust use tauri::Manager; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_thermal_printer::init()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } ``` ```toml # src-tauri/Cargo.toml [dependencies] tauri-plugin-thermal-printer = "1.3.2" ``` ```json // src-tauri/capabilities/default.json { "permissions": [ "core:default", "thermal-printer:allow-list-thermal-printers", "thermal-printer:allow-print-thermal-printer", "thermal-printer:allow-test-thermal-printer" ] } ``` -------------------------------- ### Initialize Thermal Printer Plugin in Tauri Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Integrate the thermal printer plugin into your Tauri application by adding the init() call in your main Rust file. ```rust .plugin(tauri_plugin_thermal_printer::init()) ``` -------------------------------- ### JSON Subtitle Section Example Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Define a 'Subtitle' section for a print job. This prints text with forced bold and increased height. Styles can be customized or omitted for defaults. ```json { "Subtitle": { "text": "My Subtitle", "styles": { "bold": true, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "height" } } } ``` ```json { "Subtitle": { "text": "My Subtitle" } } ``` -------------------------------- ### JSON Title Section Example Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Define a 'Title' section for a print job. This prints text with forced double size and center alignment. Styles can be customized or omitted for defaults. ```json { "Title": { "text": "My Title", "styles": { "bold": false, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double" } } } ``` ```json { "Title": { "text": "My Title" } } ``` -------------------------------- ### Format Rust Code Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/CONTRIBUTING.md Use this command to format your Rust code according to the project's style guidelines. Avoid breaking the public API. ```bash cargo fmt ``` -------------------------------- ### Apply Text Styling with Thermal Printer Source: https://context7.com/luis3132/tauri-plugin-thermal-printer/llms.txt Demonstrates various text formatting options including bold, underline, size, font, and alignment. Global styles can be set to affect all subsequent sections. ```typescript import { print_thermal_printer, text, globalStyles, line, feed, ENCODE, TEXT_ALIGN, TEXT_SIZE, TEXT_FONT } from "tauri-plugin-thermal-printer"; const styledSections = [ // Set global styles affecting all subsequent sections globalStyles({ align: TEXT_ALIGN.CENTER }), text("BOLD TEXT", { bold: true }), text("UNDERLINED TEXT", { underline: true }), text("INVERTED TEXT", { invert: true }), line("-"), // Size options: normal, height, width, double text("Normal Size", { size: TEXT_SIZE.NORMAL }), text("Double Height", { size: TEXT_SIZE.HEIGHT }), text("Double Width", { size: TEXT_SIZE.WIDTH }), text("Double Size", { size: TEXT_SIZE.DOUBLE }), line("-"), // Font options: A (default), B (smaller), C text("Font A - Default", { font: TEXT_FONT.A }), text("Font B - Smaller", { font: TEXT_FONT.B }), line("-"), // Alignment options text("Left Aligned", { align: TEXT_ALIGN.LEFT }), text("Center Aligned", { align: TEXT_ALIGN.CENTER }), text("Right Aligned", { align: TEXT_ALIGN.RIGHT }), line("-"), // Combined styles text("TOTAL: $99.99", { bold: true, size: TEXT_SIZE.DOUBLE, align: TEXT_ALIGN.RIGHT }), feed(3) ]; await print_thermal_printer({ printer: "TM-T20II", paper_size: "Mm80", options: { cut_paper: true, beep: false, open_cash_drawer: false, code_page: { code_page: 6, encode: ENCODE.WINDOWS_1252, use_gbk: false } }, sections: styledSections }); ``` -------------------------------- ### Print QR Code Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Prints a QR code with specified data, size, and error correction level. Optional alignment can be set. ```json { "Qr": { "data": "https://example.com", "size": 5, "error_correction": "M", "model": 2, "align": "center" } } ``` -------------------------------- ### Table Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Prints a table with specified columns, headers, and data. ```APIDOC ## Table ### Description Prints a table with specified columns, headers, and data. ### Method (Not specified, assumed to be part of a larger command) ### Endpoint (Not specified) ### Parameters #### Request Body - **columns** (number) - Required - Number of columns - **column_widths** (array) - Optional - Widths of each column in characters. Length must equal `columns` and the sum must equal the paper's chars/line. If omitted, columns are distributed evenly. - **header** (array) - Optional - Column headers. Must have exactly `columns` elements if provided. - **body** (array) - Required - Data rows. Each row must have exactly `columns` cells. - **truncate** (boolean) - Optional - Truncate long text instead of wrapping (default: `false`) ### Request Example ```json { "Table": { "columns": 3, "column_widths": [10, 15, 10], "header": [ {"text": "Col1"}, {"text": "Col2"}, {"text": "Col3"} ], "body": [ [ {"text": "Data1"}, {"text": "Data2"}, {"text": "Data3"} ] ], "truncate": false } } ``` ### Response (Not specified) ``` -------------------------------- ### List Available Thermal Printers Source: https://context7.com/luis3132/tauri-plugin-thermal-printer/llms.txt Retrieves a list of all configured thermal printers on the system. This function queries the operating system's printer subsystem and returns information about each printer, including its name, interface type, identifier, and status. Ensure the plugin is correctly installed and configured. ```typescript import { list_thermal_printers, type PrinterInfo } from "tauri-plugin-thermal-printer"; try { const printers: PrinterInfo[] = await list_thermal_printers(); printers.forEach(printer => { console.log(`Name: ${printer.name}`); console.log(`Interface: ${printer.interface_type}`); // "USB", "NETWORK", "BLUETOOTH" console.log(`Identifier: ${printer.identifier}`); // e.g., "usb://EPSON/TM-T20II" or "192.168.1.100:9100" console.log(`Status: ${printer.status}`); // "IDLE", "BUSY" }); } catch (error) { console.error("Failed to list printers:", error); } ``` -------------------------------- ### Set Global Styles Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Configure global styles that will be applied to subsequent text sections. This allows setting default styles like bold, underline, alignment, and font without specifying them for each text element. ```json { "GlobalStyles": { "bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal" } } ``` -------------------------------- ### Paper Sizes and TypeScript Helpers Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Information on supported paper sizes and their corresponding character counts per line and pixel widths, along with TypeScript constants and helper functions for easy integration. ```APIDOC ## Paper Sizes | Value | Paper width | Chars/line | Typical use | |-------|-------------|------------|-------------| | `"Mm40"` | 40mm | 21 | Handheld ticket printers | | `"Mm44"` | 44mm | 24 | Compact POS | | `"Mm58"` | 58mm | 32 | Small format (most common portable) | | `"Mm72"` | 72mm | 42 | Mid-range printers | | `"Mm80"` | 80mm | 48 | Standard large format (default) | | `"Mm104"` | 104mm | 62 | Wide format | ## Paper Size Helpers (TypeScript) The TypeScript package exports constants and helper functions with the same values used by the Rust backend. ```typescript import { PAPER_SIZE_CHARS_PER_LINE, PAPER_SIZE_PIXELS_WIDTH, DEFAULT_PAPER_SIZE, getPaperSizeCharsPerLine, getPaperSizePixelsWidth, type PaperSize, } from "tauri-plugin-thermal-printer"; const size: PaperSize = "Mm58"; console.log(DEFAULT_PAPER_SIZE); // "Mm80" console.log(PAPER_SIZE_CHARS_PER_LINE[size]); // 32 console.log(PAPER_SIZE_PIXELS_WIDTH[size]); // 384 // Equivalent helper functions: console.log(getPaperSizeCharsPerLine(size)); // 32 console.log(getPaperSizePixelsWidth(size)); // 384 ``` ### Values per paper size: | PaperSize | Chars/line | Pixels width | |-----------|------------|--------------| | `"Mm40"` | 21 | 256 | | `"Mm44"` | 24 | 288 | | `"Mm58"` | 32 | 384 | | `"Mm72"` | 42 | 512 | | `"Mm80"` | 48 | 576 | | `"Mm104"` | 62 | 752 | ``` -------------------------------- ### Print Table with Header Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Prints a table with a specified number of columns, column widths, header, and body content. Truncation can be enabled. ```json { "Table": { "columns": 3, "column_widths": [10, 15, 10], "header": [ {"text": "Col1"}, {"text": "Col2"}, {"text": "Col3"} ], "body": [ [ {"text": "Data1"}, {"text": "Data2"}, {"text": "Data3"} ] ], "truncate": false } } ``` -------------------------------- ### Generate Product Label (58mm) Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Use this snippet to create a print job for a 58mm product label. It includes product details, pricing, and a barcode. Ensure the printer and paper size are correctly configured. ```typescript const productLabel: PrintJobRequest = { "printer": "TM-T20II", "paper_size": "Mm58", "options": { "cut_paper": true, "beep": false, "open_cash_drawer": false }, "sections": [ {"Title": {"text": "PRODUCTO", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}}, {"Line": {"character": "-"}}, {"Text": {"text": "Nombre: Laptop HP", "styles": {"bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "Modelo: 15-dy2021la", "styles": {"bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "UPC: 7501234567890", "styles": {"bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Line": {"character": "-"}}, {"Text": {"text": "PRECIO: $12,999.00", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Line": {"character": "-"}}, {"Barcode": {"data": "7501234567890", "barcode_type": "EAN13", "width": 2, "height": 50, "text_position": "below"}}, {"Feed": {"feed_type": "lines", "value": 2}} ] }; ``` -------------------------------- ### Configure Cash Drawer Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Opens the cash drawer. Requires specifying the pin and pulse time in milliseconds. ```json { "Drawer": { "pin": 2, "pulse_time": 100 } } ``` -------------------------------- ### ESC/POS Initialize Printer Command Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md This is the ESC/POS command to initialize the printer, resetting it to its default state. ```plaintext \x1B\x40 ``` -------------------------------- ### Utilize Style Constants Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Import and use typed constant objects for text alignment, size, font, barcode types, and QR error correction to avoid typing raw strings. These constants simplify configuration. ```typescript import { TEXT_ALIGN, TEXT_SIZE, TEXT_FONT, BARCODE_TYPE, BARCODE_TEXT_POSITION, QR_ERROR_CORRECTION, IMAGE_MODE, CUT_MODE, } from "tauri-plugin-thermal-printer"; // Examples: const styles = { align: TEXT_ALIGN.CENTER, // "center" size: TEXT_SIZE.DOUBLE, // "double" font: TEXT_FONT.B, // "B" bold: true, }; const barcode = { barcode_type: BARCODE_TYPE.EAN13, // "EAN13" text_position: BARCODE_TEXT_POSITION.BELOW, // "below" }; const qr = { error_correction: QR_ERROR_CORRECTION.M, // "M" }; ``` -------------------------------- ### List Available Thermal Printers Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Use this function to retrieve a list of all printers configured on the system. Ensure the plugin is initialized. ```typescript import { list_thermal_printers } from "tauri-plugin-thermal-printer"; try { const response = await list_thermal_printers(); } catch (error) { console.log("List printers failed: " + error) } ``` -------------------------------- ### Paper Size Configuration Constants Source: https://context7.com/luis3132/tauri-plugin-thermal-printer/llms.txt Provides constants and helper functions for managing thermal paper sizes, including characters per line and pixel width calculations for layout design. ```typescript import { PAPER_SIZE_CHARS_PER_LINE, PAPER_SIZE_PIXELS_WIDTH, DEFAULT_PAPER_SIZE, getPaperSizeCharsPerLine, getPaperSizePixelsWidth, type PaperSize } from "tauri-plugin-thermal-printer"; // Available paper sizes: // Mm40 - 21 chars/line, 256 pixels (handheld ticket printers) // Mm44 - 24 chars/line, 288 pixels (compact POS) // Mm58 - 32 chars/line, 384 pixels (most common portable) // Mm72 - 42 chars/line, 512 pixels (mid-range printers) // Mm80 - 48 chars/line, 576 pixels (standard large format - default) // Mm104 - 62 chars/line, 752 pixels (wide format) const size: PaperSize = "Mm58"; console.log(DEFAULT_PAPER_SIZE); // "Mm80" console.log(PAPER_SIZE_CHARS_PER_LINE[size]); // 32 console.log(PAPER_SIZE_PIXELS_WIDTH[size]); // 384 console.log(getPaperSizeCharsPerLine(size)); // 32 console.log(getPaperSizePixelsWidth(size)); // 384 // Use chars_per_line to calculate table column widths const paperSize: PaperSize = "Mm80"; const totalChars = getPaperSizeCharsPerLine(paperSize); // 48 const columnWidths = [6, 28, 14]; // Must sum to 48 for Mm80 console.log(columnWidths.reduce((a, b) => a + b)); // 48 ``` -------------------------------- ### Build Print Sections with Helpers Source: https://context7.com/luis3132/tauri-plugin-thermal-printer/llms.txt Utilize these helper functions to construct print sections, reducing boilerplate code. Each helper returns a typed `PrintSections` object with default settings. ```typescript import { title, subtitle, text, line, feed, cut, globalStyles, beep, drawer, table, qr, barcode, dataMatrix, pdf417, image, logo, TEXT_ALIGN, TEXT_SIZE, BARCODE_TYPE, QR_ERROR_CORRECTION, IMAGE_MODE, print_thermal_printer, ENCODE, type PrintJobRequest } from "tauri-plugin-thermal-printer"; const sections = [ globalStyles({ align: TEXT_ALIGN.LEFT }), title("RESTAURANT ORDER"), subtitle("Table 12 - Order #456"), line("="), table(3, [ [text("2"), text("Burger"), text("$15.00", { align: TEXT_ALIGN.RIGHT })], [text("1"), text("Fries"), text("$5.00", { align: TEXT_ALIGN.RIGHT })], [text("2"), text("Soda"), text("$6.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: $26.00", { bold: true, size: TEXT_SIZE.DOUBLE, align: TEXT_ALIGN.RIGHT }), qr("https://restaurant.com/order/456", { size: 6, error_correction: QR_ERROR_CORRECTION.M, model: 2, align: TEXT_ALIGN.CENTER }), barcode("456789012345", BARCODE_TYPE.EAN13, { width: 3, height: 70, text_position: "below", align: TEXT_ALIGN.CENTER }), beep(1, 3), feed(3), cut() ]; const job: PrintJobRequest = { printer: "TM-T20II", paper_size: "Mm80", options: { cut_paper: true, beep: false, open_cash_drawer: false, code_page: { code_page: 6, encode: ENCODE.WINDOWS_1252, use_gbk: false } }, sections }; await print_thermal_printer(job); ``` -------------------------------- ### DataMatrix Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Prints a DataMatrix code. ```APIDOC ## DataMatrix ### Description Prints a DataMatrix code. ### Method (Not specified, assumed to be part of a larger command) ### Endpoint (Not specified) ### Parameters #### Request Body - **data** (string) - Required - DataMatrix data - **size** (number) - Required - Module size (1-16) ### Request Example ```json { "DataMatrix": { "data": "DataMatrix data", "size": 5 } } ``` ### Response (Not specified) ``` -------------------------------- ### Image Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Prints an image from base64 data. ```APIDOC ## Image ### Description Prints an image from base64 data. ### Method (Not specified, assumed to be part of a larger command) ### Endpoint (Not specified) ### Parameters #### Request Body - **data** (string) - Required - Base64 encoded image. Must not be empty. - **max_width** (number) - Required - Maximum width in pixels (0 or values larger than the paper width are clamped to the paper width automatically) - **align** (string) - Required - Alignment: `"left"`, `"center"`, `"right"` - **dithering** (boolean) - Required - Apply Floyd-Steinberg dithering for better quality on monochrome printers - **size** (string) - Required - Print size: `"normal"`, `"double_width"`, `"double_height"`, `"quadruple"` ### Request Example ```json { "Image": { "data": "base64_encoded_image", "max_width": 384, "align": "center", "dithering": true, "size": "normal" } } ``` ### Response (Not specified) ``` -------------------------------- ### Style Constants Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Importable typed constants for various style properties. ```APIDOC ### Style Constants Instead of typing raw strings, you can import typed constant objects for various properties. **Available Exports:** - `TEXT_ALIGN`: `LEFT`, `CENTER`, `RIGHT` - `TEXT_SIZE`: `NORMAL`, `HEIGHT`, `WIDTH`, `DOUBLE` - `TEXT_FONT`: `A`, `B`, `C` - `BARCODE_TYPE`: `UPC_A`, `UPC_E`, `EAN13`, `EAN8`, `CODE39`, `ITF`, `CODABAR`, `CODE93`, `CODE128` - `BARCODE_TEXT_POSITION`: `NONE`, `ABOVE`, `BELOW`, `BOTH` - `QR_ERROR_CORRECTION`: `L`, `M`, `Q`, `H` - `IMAGE_MODE`: `NORMAL`, `DOUBLE_WIDTH`, `DOUBLE_HEIGHT`, `QUADRUPLE` - `CUT_MODE`: `FULL`, `PARTIAL` **Example Usage:** ```typescript import { TEXT_ALIGN, TEXT_SIZE, TEXT_FONT, } from "tauri-plugin-thermal-printer"; const styles = { align: TEXT_ALIGN.CENTER, // "center" size: TEXT_SIZE.DOUBLE, // "double" font: TEXT_FONT.B, // "B" }; ``` ``` -------------------------------- ### Configure Beep Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Sets the printer to emit a beep. Specify the number of times and duration in milliseconds. ```json { "Beep": { "times": 1, "duration": 100 } } ``` -------------------------------- ### Print DataMatrix Code Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Prints a DataMatrix code with the specified data and module size. ```json { "DataMatrix": { "data": "DataMatrix data", "size": 5 } } ``` -------------------------------- ### Generate Long Receipt (Supermarket - 80mm) Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md This snippet shows how to construct a detailed supermarket receipt with various sections like store information, ticket details, and a product table. Ensure the printer name and paper size are correctly configured. ```typescript import { print_thermal_printer, type PrintJobRequest } from "tauri-plugin-thermal-printer"; const receipt: PrintJobRequest = { "printer": "TM-T20II", "paper_size": "Mm80", "options": { "cut_paper": true, "beep": false, "open_cash_drawer": false }, "sections": [ {"Title": {"text": "SUPERMERCADO LA ECONOMÍA", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}}, {"Text": {"text": "Sucursal Centro", "styles": {"bold": false, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "Av. Juárez #1234, Col. Centro", "styles": {"bold": false, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "Tel: (555) 123-4567", "styles": {"bold": false, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "RFC: SUPE850101ABC", "styles": {"bold": false, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Line": {"character": "="}}, {"Text": {"text": "TICKET DE COMPRA", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "Fecha: 14/10/2025 15:45:30", "styles": {"bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "Ticket: #0012345", "styles": {"bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "Cajero: María González", "styles": {"bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Text": {"text": "Caja: 03", "styles": {"bold": false, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}}, {"Line": {"character": "="}}, {"Table": { "columns": 4, "column_widths": [5, 20, 11, 12], "header": [ {"text": "CANT", "styles": {"bold": true, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}, {"text": "DESCRIPCIÓN", "styles": {"bold": true, "underline": false, "align": "left", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}, {"text": "P.U.", "styles": {"bold": true, "underline": false, "align": "right", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}, {"text": "TOTAL", "styles": {"bold": true, "underline": false, "align": "right", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}} ], "body": [ [ {"text": "2", "styles": null}, {"text": "Leche Lala 1L", "styles": null}, {"text": "$22.50", "styles": {"bold": false, "underline": false, "align": "right", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}, {"text": "$45.00", "styles": {"bold": false, "underline": false, "align": "right", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}} ], [ {"text": "1", "styles": null}, {"text": "Pan Bimbo Blanco", "styles": null}, {"text": "$38.00", "styles": {"bold": false, "underline": false, "align": "right", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}, {"text": "$38.00", "styles": {"bold": false, "underline": false, "align": "right", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}} ], [ {"text": "3", "styles": null}, {"text": "Coca Cola 600ml", "styles": null}, {"text": "$16.00", "styles": {"bold": false, "underline": false, "align": "right", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "normal"}}, ``` -------------------------------- ### TypeScript Paper Size Helpers Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Import and use constants and helper functions for paper sizes in TypeScript. These provide character counts per line and pixel widths for various paper sizes. ```typescript import { PAPER_SIZE_CHARS_PER_LINE, PAPER_SIZE_PIXELS_WIDTH, DEFAULT_PAPER_SIZE, getPaperSizeCharsPerLine, getPaperSizePixelsWidth, type PaperSize, } from "tauri-plugin-thermal-printer"; const size: PaperSize = "Mm58"; console.log(DEFAULT_PAPER_SIZE); // "Mm80" console.log(PAPER_SIZE_CHARS_PER_LINE[size]); // 32 console.log(PAPER_SIZE_PIXELS_WIDTH[size]); // 384 // Equivalent helper functions: console.log(getPaperSizeCharsPerLine(size)); // 32 console.log(getPaperSizePixelsWidth(size)); // 384 ``` -------------------------------- ### Local Path Dependency in Tauri TOML Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Configure your Tauri project's Cargo.toml to use the locally cloned plugin via a path dependency. ```toml [dependencies] tauri-plugin-thermal-printer = { path = "../../tauri-plugin-thermal-printer" } ``` -------------------------------- ### Local Path Dependency in Package JSON Source: https://github.com/luis3132/tauri-plugin-thermal-printer/blob/main/README.md Configure your Tauri project's package.json to use the locally cloned plugin via a file path. ```json "dependencies": { "tauri-plugin-thermal-printer": "file:../tauri-plugin-thermal-printer" } ```