tauri-plugin-thermal-printer 1.3.2 → 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 +46 -66
- package/dist-js/index.d.ts +2 -9
- 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 |
|
|
@@ -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"}},
|
|
@@ -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,11 +383,7 @@ 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 | Cut paper after printing (default: `true`) |
|
|
395
|
-
| `options.beep` | boolean | ❌ No | Beep after printing (default: `false`) |
|
|
396
|
-
| `options.open_cash_drawer` | boolean | ❌ No | Open cash drawer after printing (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
389
|
#### Paper Sizes
|
|
@@ -897,14 +886,9 @@ Each printer model assigns its own `ESC t n` values, so `CodePage.code_page` acc
|
|
|
897
886
|
import { ENCODE, type CodePage } from "tauri-plugin-thermal-printer";
|
|
898
887
|
|
|
899
888
|
const options = {
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
code_page: {
|
|
904
|
-
code_page: 6,
|
|
905
|
-
encode: ENCODE.WINDOWS_1252,
|
|
906
|
-
use_gbk: false,
|
|
907
|
-
}, // sends ESC t 6
|
|
889
|
+
code_page: 6,
|
|
890
|
+
encode: ENCODE.WINDOWS_1252,
|
|
891
|
+
use_gbk: false,
|
|
908
892
|
};
|
|
909
893
|
```
|
|
910
894
|
|
|
@@ -1068,14 +1052,9 @@ const job: PrintJobRequest = {
|
|
|
1068
1052
|
printer: "TM-T20II",
|
|
1069
1053
|
paper_size: "Mm80",
|
|
1070
1054
|
options: {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
code_page: {
|
|
1075
|
-
code_page: 6,
|
|
1076
|
-
encode: ENCODE.WINDOWS_1252,
|
|
1077
|
-
use_gbk: false,
|
|
1078
|
-
},
|
|
1055
|
+
code_page: 0,
|
|
1056
|
+
encode: ENCODE.ACCENT_REMOVER,
|
|
1057
|
+
use_gbk: false,
|
|
1079
1058
|
},
|
|
1080
1059
|
sections: [
|
|
1081
1060
|
globalStyles({ align: TEXT_ALIGN.LEFT }),
|
|
@@ -1144,7 +1123,7 @@ await print_thermal_printer(job);
|
|
|
1144
1123
|
|
|
1145
1124
|
This section contains practical examples for different use cases. Each example demonstrates how to structure print jobs for various business scenarios.
|
|
1146
1125
|
|
|
1147
|
-
> **NOTE:**
|
|
1126
|
+
> **NOTE:** With default options, a tail `Cut` section is appended automatically as `{ "Cut": { "mode": "partial", "feed": 0 } }`. Add your own `Cut` section when you need an extra cut or different parameters.
|
|
1148
1127
|
|
|
1149
1128
|
### 🛒 Long Receipt (Supermarket - 80mm)
|
|
1150
1129
|
|
|
@@ -1155,9 +1134,9 @@ const receipt: PrintJobRequest = {
|
|
|
1155
1134
|
"printer": "TM-T20II",
|
|
1156
1135
|
"paper_size": "Mm80",
|
|
1157
1136
|
"options": {
|
|
1158
|
-
"
|
|
1159
|
-
"
|
|
1160
|
-
"
|
|
1137
|
+
"code_page": 0,
|
|
1138
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1139
|
+
"use_gbk": false,
|
|
1161
1140
|
},
|
|
1162
1141
|
"sections": [
|
|
1163
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"}}},
|
|
@@ -1277,9 +1256,9 @@ const restaurantTicket: PrintJobRequest = {
|
|
|
1277
1256
|
"printer": "TM-T20II",
|
|
1278
1257
|
"paper_size": "Mm80",
|
|
1279
1258
|
"options": {
|
|
1280
|
-
"
|
|
1281
|
-
"
|
|
1282
|
-
"
|
|
1259
|
+
"code_page": 0,
|
|
1260
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1261
|
+
"use_gbk": false,
|
|
1283
1262
|
},
|
|
1284
1263
|
"sections": [
|
|
1285
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"}}},
|
|
@@ -1364,9 +1343,9 @@ const kitchenOrder: PrintJobRequest = {
|
|
|
1364
1343
|
"printer": "TM-T20II",
|
|
1365
1344
|
"paper_size": "Mm80",
|
|
1366
1345
|
"options": {
|
|
1367
|
-
"
|
|
1368
|
-
"
|
|
1369
|
-
"
|
|
1346
|
+
"code_page": 0,
|
|
1347
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1348
|
+
"use_gbk": false,
|
|
1370
1349
|
},
|
|
1371
1350
|
"sections": [
|
|
1372
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"}}},
|
|
@@ -1402,9 +1381,9 @@ const productLabel: PrintJobRequest = {
|
|
|
1402
1381
|
"printer": "TM-T20II",
|
|
1403
1382
|
"paper_size": "Mm58",
|
|
1404
1383
|
"options": {
|
|
1405
|
-
"
|
|
1406
|
-
"
|
|
1407
|
-
"
|
|
1384
|
+
"code_page": 0,
|
|
1385
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1386
|
+
"use_gbk": false,
|
|
1408
1387
|
},
|
|
1409
1388
|
"sections": [
|
|
1410
1389
|
{"Title": {"text": "PRODUCTO", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
|
@@ -1430,9 +1409,9 @@ const turnTicket: PrintJobRequest = {
|
|
|
1430
1409
|
"printer": "TM-T20II",
|
|
1431
1410
|
"paper_size": "Mm58",
|
|
1432
1411
|
"options": {
|
|
1433
|
-
"
|
|
1434
|
-
"
|
|
1435
|
-
"
|
|
1412
|
+
"code_page": 0,
|
|
1413
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1414
|
+
"use_gbk": false,
|
|
1436
1415
|
},
|
|
1437
1416
|
"sections": [
|
|
1438
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"}}},
|
|
@@ -1463,9 +1442,9 @@ const parkingTicket: PrintJobRequest = {
|
|
|
1463
1442
|
"printer": "TM-T20II",
|
|
1464
1443
|
"paper_size": "Mm80",
|
|
1465
1444
|
"options": {
|
|
1466
|
-
"
|
|
1467
|
-
"
|
|
1468
|
-
"
|
|
1445
|
+
"code_page": 0,
|
|
1446
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1447
|
+
"use_gbk": false,
|
|
1469
1448
|
},
|
|
1470
1449
|
"sections": [
|
|
1471
1450
|
{"Title": {"text": "ESTACIONAMIENTO", "styles": {"bold": true, "underline": false, "align": "center", "italic": false, "invert": false, "font": "A", "rotate": false, "upside_down": false, "size": "Double"}}},
|
|
@@ -1500,9 +1479,9 @@ const eventTicket: PrintJobRequest = {
|
|
|
1500
1479
|
"printer": "TM-T20II",
|
|
1501
1480
|
"paper_size": "Mm80",
|
|
1502
1481
|
"options": {
|
|
1503
|
-
"
|
|
1504
|
-
"
|
|
1505
|
-
"
|
|
1482
|
+
"code_page": 0,
|
|
1483
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1484
|
+
"use_gbk": false,
|
|
1506
1485
|
},
|
|
1507
1486
|
"sections": [
|
|
1508
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"}}},
|
|
@@ -1559,9 +1538,9 @@ const paymentReceipt: PrintJobRequest = {
|
|
|
1559
1538
|
"printer": "TM-T20II",
|
|
1560
1539
|
"paper_size": "Mm80",
|
|
1561
1540
|
"options": {
|
|
1562
|
-
"
|
|
1563
|
-
"
|
|
1564
|
-
"
|
|
1541
|
+
"code_page": 0,
|
|
1542
|
+
"encode": ENCODE.ACCENT_REMOVER,
|
|
1543
|
+
"use_gbk": false,
|
|
1565
1544
|
},
|
|
1566
1545
|
"sections": [
|
|
1567
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"}}},
|
|
@@ -1625,5 +1604,6 @@ const paymentReceipt: PrintJobRequest = {
|
|
|
1625
1604
|
- No need to manually reset styles
|
|
1626
1605
|
|
|
1627
1606
|
#### Paper Cutting
|
|
1628
|
-
- **Automatic**:
|
|
1629
|
-
- **Manual
|
|
1607
|
+
- **Automatic**: `options.cut_paper = true` appends a tail `Cut` section with `mode: "partial"` and `feed: 0`
|
|
1608
|
+
- **Manual**: Add a `Cut` section anywhere in `sections` to issue explicit cut commands
|
|
1609
|
+
- **Combined**: Automatic and manual cuts are both emitted when both are present
|
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,13 +92,6 @@ export declare const CUT_MODE: {
|
|
|
92
92
|
readonly FULL: CutMode;
|
|
93
93
|
readonly PARTIAL: CutMode;
|
|
94
94
|
};
|
|
95
|
-
export interface PrinterOptions {
|
|
96
|
-
cut_paper: boolean;
|
|
97
|
-
beep: boolean;
|
|
98
|
-
open_cash_drawer: boolean;
|
|
99
|
-
/** Required ESC/POS page plus host-side encoding strategy. */
|
|
100
|
-
code_page: CodePage;
|
|
101
|
-
}
|
|
102
95
|
export interface GlobalStyles {
|
|
103
96
|
bold?: boolean;
|
|
104
97
|
underline?: boolean;
|
|
@@ -237,7 +230,7 @@ export type PrintSections = {
|
|
|
237
230
|
export interface PrintJobRequest {
|
|
238
231
|
printer: string;
|
|
239
232
|
sections: PrintSections[];
|
|
240
|
-
options:
|
|
233
|
+
options: CodePage;
|
|
241
234
|
paper_size: PaperSize;
|
|
242
235
|
}
|
|
243
236
|
export interface PrinterInfo {
|