tauri-plugin-thermal-printer 1.3.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -72
- package/dist-js/index.d.ts +2 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Tauri Plugin thermal-printer
|
|
2
2
|
|
|
3
|
+
> **BREAKING CHANGES:** The 2.0.0 and newer versions **removed** the `PrinterOptions` interface to simplify configuration. The `options` field in `PrintJobRequest` now directly accepts a `CodePage` object.
|
|
4
|
+
> The shorthand options (`cut_paper`, `beep`, and `open_cash_drawer`) have been **removed**. If you need these actions, explicitly append them as sections (e.g., `{"Cut": {"mode": "partial", "feed": 0}}`) at the end of your `sections` array.
|
|
5
|
+
|
|
3
6
|
This plugin provides thermal printer functionality for Tauri applications, allowing you to print documents, test printers, and list available printers.
|
|
4
7
|
|
|
5
8
|
| Platform | Supported |
|
|
@@ -90,7 +93,7 @@ pub fn generate_document(&mut self, print_job: &PrintJobRequest) -> Result<Vec<u
|
|
|
90
93
|
#### 4. **OS Integration** (`src/desktop_printers/` and `android/`)
|
|
91
94
|
- **Linux/macOS**: Uses CUPS system (`lpstat`, `lp` commands)
|
|
92
95
|
- **Windows**: Uses WinAPI (Windows API) to directly access system printers via functions such as EnumPrintersW for listing printers, OpenPrinterW for opening printer handles, and WritePrinter for sending raw data
|
|
93
|
-
- **Android**: Kotlin plugin with Bluetooth SPP
|
|
96
|
+
- **Android**: Kotlin plugin with Bluetooth SPP and USB printer discovery and printing
|
|
94
97
|
|
|
95
98
|
### Workflow
|
|
96
99
|
|
|
@@ -106,8 +109,8 @@ pub fn generate_document(&mut self, print_job: &PrintJobRequest) -> Result<Vec<u
|
|
|
106
109
|
|
|
107
110
|
1. **Frontend** sends `PrintJobRequest` with sections and configuration
|
|
108
111
|
2. **Rust** generates ESC/POS binary data using the same `ProcessPrint` pipeline
|
|
109
|
-
3. **Kotlin plugin** receives the binary data and the printer
|
|
110
|
-
4.
|
|
112
|
+
3. **Kotlin plugin** receives the binary data and the printer MAC address
|
|
113
|
+
4. **Bluetooth SPP** connection is established to the printer
|
|
111
114
|
5. **Thermal Printer** interprets ESC/POS commands and prints
|
|
112
115
|
|
|
113
116
|
#### Print Structure Example:
|
|
@@ -116,8 +119,8 @@ pub fn generate_document(&mut self, print_job: &PrintJobRequest) -> Result<Vec<u
|
|
|
116
119
|
"printer": "TM-T20II",
|
|
117
120
|
"paper_size": "Mm80",
|
|
118
121
|
"options": {
|
|
119
|
-
"
|
|
120
|
-
"
|
|
122
|
+
"code_page": 6,
|
|
123
|
+
"encode": "WINDOWS_1252"
|
|
121
124
|
},
|
|
122
125
|
"sections": [
|
|
123
126
|
{"Title": {"text": "My Title"}},
|
|
@@ -150,18 +153,18 @@ The plugin translates all sections into **ESC/POS** (Escape Sequence for Point o
|
|
|
150
153
|
- ✅ **Linux**: Fully functional (CUPS)
|
|
151
154
|
- ✅ **macOS**: Fully functional (CUPS)
|
|
152
155
|
- ✅ **Windows**: Fully functional (WinAPI)
|
|
153
|
-
- ✅ **Android**: Bluetooth
|
|
156
|
+
- ✅ **Android**: Bluetooth and USB printer discovery and printing
|
|
154
157
|
- ❌ **iOS**: Not implemented
|
|
155
158
|
|
|
156
159
|
### Supported Connections
|
|
157
160
|
|
|
158
161
|
| Connection | Linux | macOS | Windows | Android |
|
|
159
162
|
| ---------- | ----- | ----- | ------- | ------- |
|
|
160
|
-
| USB | ✅ | ✅ | ✅ | ✅
|
|
161
|
-
| Network | ✅ | ✅ | ✅ |
|
|
163
|
+
| USB | ✅ | ✅ | ✅ | ✅ (discovery only) |
|
|
164
|
+
| Network | ✅ | ✅ | ✅ | ❌ |
|
|
162
165
|
| Bluetooth | ❌ | ❌ | ❌ | ✅ |
|
|
163
166
|
|
|
164
|
-
> **Android note**: The `printer` field in `PrintJobRequest` must be the
|
|
167
|
+
> **Android note**: The `printer` field in `PrintJobRequest` must be the Bluetooth MAC address of the printer (e.g. `"AA:BB:CC:DD:EE:FF"`). The printer must be previously paired in the Android Bluetooth settings. Bluetooth permissions are requested automatically at runtime.
|
|
165
168
|
|
|
166
169
|
## Installation
|
|
167
170
|
|
|
@@ -281,14 +284,9 @@ try { await test_thermal_printer({
|
|
|
281
284
|
"printer": "TM-T20II",
|
|
282
285
|
"paper_size": "Mm80",
|
|
283
286
|
"options": {
|
|
284
|
-
"
|
|
285
|
-
"
|
|
286
|
-
"
|
|
287
|
-
"code_page": {
|
|
288
|
-
"code_page": 6,
|
|
289
|
-
"encode": ENCODE.WINDOWS_1252,
|
|
290
|
-
"use_gbk": false
|
|
291
|
-
}
|
|
287
|
+
"code_page": 6,
|
|
288
|
+
"encode": ENCODE.WINDOWS_1252,
|
|
289
|
+
"use_gbk": false
|
|
292
290
|
},
|
|
293
291
|
"sections": [] // it's not going to print anything
|
|
294
292
|
},
|
|
@@ -352,14 +350,9 @@ try { await print_thermal_printer({
|
|
|
352
350
|
"printer": "TM-T20II",
|
|
353
351
|
"paper_size": "Mm80",
|
|
354
352
|
"options": {
|
|
355
|
-
"
|
|
356
|
-
"
|
|
357
|
-
"
|
|
358
|
-
"code_page": {
|
|
359
|
-
"code_page": 6,
|
|
360
|
-
"encode": ENCODE.WINDOWS_1252,
|
|
361
|
-
"use_gbk": false
|
|
362
|
-
}
|
|
353
|
+
"code_page": 6,
|
|
354
|
+
"encode": ENCODE.WINDOWS_1252,
|
|
355
|
+
"use_gbk": false
|
|
363
356
|
},
|
|
364
357
|
"sections": [
|
|
365
358
|
{"Title": {"text": "My Business"}},
|
|
@@ -390,15 +383,9 @@ Returns `Promise<void>`. Resolves when printing completes successfully. **Throws
|
|
|
390
383
|
|-----------|------|----------|-------------|
|
|
391
384
|
| `printer` | string | ✅ Yes | Printer name |
|
|
392
385
|
| `paper_size` | PaperSize | ❌ No | Paper size (default: `"Mm80"`) — see [Paper Sizes](#paper-sizes) |
|
|
393
|
-
| `options` |
|
|
394
|
-
| `options.cut_paper` | boolean | ❌ No | Append a tail `Cut` section equivalent to `{ "Cut": { "mode": "partial", "feed": 0 } }` (default: `true`) |
|
|
395
|
-
| `options.beep` | boolean | ❌ No | Append a tail `Beep` section equivalent to `{ "Beep": { "times": 1, "duration": 3 } }` (default: `false`) |
|
|
396
|
-
| `options.open_cash_drawer` | boolean | ❌ No | Append a tail `Drawer` section equivalent to `{ "Drawer": { "pin": 2, "pulse_time": 100 } }` (default: `false`) |
|
|
397
|
-
| `options.code_page` | CodePage | ✅ Yes | Required ESC/POS page selection plus host-side encoding strategy — see [CodePage](#codepage) |
|
|
386
|
+
| `options` | CodePage | ✅ Yes | Required ESC/POS page selection plus host-side encoding strategy — see [CodePage](#codepage) |
|
|
398
387
|
| `sections` | array | ✅ Yes | Array of sections to print (see [Section Types](#section-types)) |
|
|
399
388
|
|
|
400
|
-
`options.cut_paper`, `options.beep`, and `options.open_cash_drawer` are tail-action shorthands. They append sections at the end of the document in this fixed order: `Beep` → `Cut` → `Drawer`. They do **not** disable or replace manually declared sections, so if you specify both, both actions are emitted.
|
|
401
|
-
|
|
402
389
|
#### Paper Sizes
|
|
403
390
|
|
|
404
391
|
| Value | Paper width | Chars/line | Typical use |
|
|
@@ -899,14 +886,9 @@ Each printer model assigns its own `ESC t n` values, so `CodePage.code_page` acc
|
|
|
899
886
|
import { ENCODE, type CodePage } from "tauri-plugin-thermal-printer";
|
|
900
887
|
|
|
901
888
|
const options = {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
code_page: {
|
|
906
|
-
code_page: 6,
|
|
907
|
-
encode: ENCODE.WINDOWS_1252,
|
|
908
|
-
use_gbk: false,
|
|
909
|
-
}, // sends ESC t 6
|
|
889
|
+
code_page: 6,
|
|
890
|
+
encode: ENCODE.WINDOWS_1252,
|
|
891
|
+
use_gbk: false,
|
|
910
892
|
};
|
|
911
893
|
```
|
|
912
894
|
|
|
@@ -1070,14 +1052,9 @@ const job: PrintJobRequest = {
|
|
|
1070
1052
|
printer: "TM-T20II",
|
|
1071
1053
|
paper_size: "Mm80",
|
|
1072
1054
|
options: {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
code_page: {
|
|
1077
|
-
code_page: 6,
|
|
1078
|
-
encode: ENCODE.WINDOWS_1252,
|
|
1079
|
-
use_gbk: false,
|
|
1080
|
-
},
|
|
1055
|
+
code_page: 0,
|
|
1056
|
+
encode: ENCODE.ACCENT_REMOVER,
|
|
1057
|
+
use_gbk: false,
|
|
1081
1058
|
},
|
|
1082
1059
|
sections: [
|
|
1083
1060
|
globalStyles({ align: TEXT_ALIGN.LEFT }),
|
|
@@ -1157,9 +1134,9 @@ const receipt: PrintJobRequest = {
|
|
|
1157
1134
|
"printer": "TM-T20II",
|
|
1158
1135
|
"paper_size": "Mm80",
|
|
1159
1136
|
"options": {
|
|
1160
|
-
"
|
|
1161
|
-
"
|
|
1162
|
-
"
|
|
1137
|
+
"code_page": 0,
|
|
1138
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1139
|
+
"use_gbk": false,
|
|
1163
1140
|
},
|
|
1164
1141
|
"sections": [
|
|
1165
1142
|
{"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"}}},
|
|
@@ -1279,9 +1256,9 @@ const restaurantTicket: PrintJobRequest = {
|
|
|
1279
1256
|
"printer": "TM-T20II",
|
|
1280
1257
|
"paper_size": "Mm80",
|
|
1281
1258
|
"options": {
|
|
1282
|
-
"
|
|
1283
|
-
"
|
|
1284
|
-
"
|
|
1259
|
+
"code_page": 0,
|
|
1260
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1261
|
+
"use_gbk": false,
|
|
1285
1262
|
},
|
|
1286
1263
|
"sections": [
|
|
1287
1264
|
{"Title": {"text": "RESTAURANTE EL BUEN SABOR", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
|
@@ -1366,9 +1343,9 @@ const kitchenOrder: PrintJobRequest = {
|
|
|
1366
1343
|
"printer": "TM-T20II",
|
|
1367
1344
|
"paper_size": "Mm80",
|
|
1368
1345
|
"options": {
|
|
1369
|
-
"
|
|
1370
|
-
"
|
|
1371
|
-
"
|
|
1346
|
+
"code_page": 0,
|
|
1347
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1348
|
+
"use_gbk": false,
|
|
1372
1349
|
},
|
|
1373
1350
|
"sections": [
|
|
1374
1351
|
{"Title": {"text": "*** COMANDA COCINA ***", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
|
@@ -1404,9 +1381,9 @@ const productLabel: PrintJobRequest = {
|
|
|
1404
1381
|
"printer": "TM-T20II",
|
|
1405
1382
|
"paper_size": "Mm58",
|
|
1406
1383
|
"options": {
|
|
1407
|
-
"
|
|
1408
|
-
"
|
|
1409
|
-
"
|
|
1384
|
+
"code_page": 0,
|
|
1385
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1386
|
+
"use_gbk": false,
|
|
1410
1387
|
},
|
|
1411
1388
|
"sections": [
|
|
1412
1389
|
{"Title": {"text": "PRODUCTO", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
|
@@ -1432,9 +1409,9 @@ const turnTicket: PrintJobRequest = {
|
|
|
1432
1409
|
"printer": "TM-T20II",
|
|
1433
1410
|
"paper_size": "Mm58",
|
|
1434
1411
|
"options": {
|
|
1435
|
-
"
|
|
1436
|
-
"
|
|
1437
|
-
"
|
|
1412
|
+
"code_page": 0,
|
|
1413
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1414
|
+
"use_gbk": false,
|
|
1438
1415
|
},
|
|
1439
1416
|
"sections": [
|
|
1440
1417
|
{"Title": {"text": "TICKET DE TURNO", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
|
@@ -1465,9 +1442,9 @@ const parkingTicket: PrintJobRequest = {
|
|
|
1465
1442
|
"printer": "TM-T20II",
|
|
1466
1443
|
"paper_size": "Mm80",
|
|
1467
1444
|
"options": {
|
|
1468
|
-
"
|
|
1469
|
-
"
|
|
1470
|
-
"
|
|
1445
|
+
"code_page": 0,
|
|
1446
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1447
|
+
"use_gbk": false,
|
|
1471
1448
|
},
|
|
1472
1449
|
"sections": [
|
|
1473
1450
|
{"Title": {"text": "ESTACIONAMIENTO", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
|
@@ -1502,9 +1479,9 @@ const eventTicket: PrintJobRequest = {
|
|
|
1502
1479
|
"printer": "TM-T20II",
|
|
1503
1480
|
"paper_size": "Mm80",
|
|
1504
1481
|
"options": {
|
|
1505
|
-
"
|
|
1506
|
-
"
|
|
1507
|
-
"
|
|
1482
|
+
"code_page": 0,
|
|
1483
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1484
|
+
"use_gbk": false,
|
|
1508
1485
|
},
|
|
1509
1486
|
"sections": [
|
|
1510
1487
|
{"Title": {"text": "CONCIERTO 2025", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
|
@@ -1561,9 +1538,9 @@ const paymentReceipt: PrintJobRequest = {
|
|
|
1561
1538
|
"printer": "TM-T20II",
|
|
1562
1539
|
"paper_size": "Mm80",
|
|
1563
1540
|
"options": {
|
|
1564
|
-
"
|
|
1565
|
-
"
|
|
1566
|
-
"
|
|
1541
|
+
"code_page": 0,
|
|
1542
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1543
|
+
"use_gbk": false,
|
|
1567
1544
|
},
|
|
1568
1545
|
"sections": [
|
|
1569
1546
|
{"Title": {"text": "COMPROBANTE DE PAGO", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
package/dist-js/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare function getPaperSizePixelsWidth(paperSize: PaperSize): number;
|
|
|
10
10
|
/**
|
|
11
11
|
* ESC/POS page selection plus explicit host-side encoding behavior.
|
|
12
12
|
*
|
|
13
|
-
* - `
|
|
13
|
+
* - `code_page` controls the `ESC t n` command sent to the printer. Default is 0.
|
|
14
14
|
* - `encode` selects the host-side encoding and defaults to
|
|
15
15
|
* `ENCODE.ACCENT_REMOVER`.
|
|
16
16
|
* - `use_gbk` controls whether unmapped non-ASCII characters may fall back
|
|
@@ -92,16 +92,6 @@ export declare const CUT_MODE: {
|
|
|
92
92
|
readonly FULL: CutMode;
|
|
93
93
|
readonly PARTIAL: CutMode;
|
|
94
94
|
};
|
|
95
|
-
export interface PrinterOptions {
|
|
96
|
-
/** Append a tail `Cut` section with mode `"partial"` and feed `0`. */
|
|
97
|
-
cut_paper: boolean;
|
|
98
|
-
/** Append a tail `Beep` section with times `1` and duration `3`. */
|
|
99
|
-
beep: boolean;
|
|
100
|
-
/** Append a tail `Drawer` section with pin `2` and pulse time `100`. */
|
|
101
|
-
open_cash_drawer: boolean;
|
|
102
|
-
/** Required ESC/POS page plus host-side encoding strategy. */
|
|
103
|
-
code_page: CodePage;
|
|
104
|
-
}
|
|
105
95
|
export interface GlobalStyles {
|
|
106
96
|
bold?: boolean;
|
|
107
97
|
underline?: boolean;
|
|
@@ -240,7 +230,7 @@ export type PrintSections = {
|
|
|
240
230
|
export interface PrintJobRequest {
|
|
241
231
|
printer: string;
|
|
242
232
|
sections: PrintSections[];
|
|
243
|
-
options:
|
|
233
|
+
options: CodePage;
|
|
244
234
|
paper_size: PaperSize;
|
|
245
235
|
}
|
|
246
236
|
export interface PrinterInfo {
|