tauri-plugin-thermal-printer 1.3.1 → 1.3.3

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 CHANGED
@@ -90,7 +90,7 @@ pub fn generate_document(&mut self, print_job: &PrintJobRequest) -> Result<Vec<u
90
90
  #### 4. **OS Integration** (`src/desktop_printers/` and `android/`)
91
91
  - **Linux/macOS**: Uses CUPS system (`lpstat`, `lp` commands)
92
92
  - **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 and USB printer discovery and printing
93
+ - **Android**: Kotlin plugin with Bluetooth SPP, USB, and Network (TCP/IP) printer discovery and printing
94
94
 
95
95
  ### Workflow
96
96
 
@@ -106,8 +106,8 @@ pub fn generate_document(&mut self, print_job: &PrintJobRequest) -> Result<Vec<u
106
106
 
107
107
  1. **Frontend** sends `PrintJobRequest` with sections and configuration
108
108
  2. **Rust** generates ESC/POS binary data using the same `ProcessPrint` pipeline
109
- 3. **Kotlin plugin** receives the binary data and the printer MAC address
110
- 4. **Bluetooth SPP** connection is established to the printer
109
+ 3. **Kotlin plugin** receives the binary data and the printer identifier (MAC, USB VID:PID, or IP:PORT)
110
+ 4. Connection is established via **Bluetooth SPP**, **USB Bulk Transfer**, or **TCP Socket**
111
111
  5. **Thermal Printer** interprets ESC/POS commands and prints
112
112
 
113
113
  #### Print Structure Example:
@@ -150,18 +150,18 @@ The plugin translates all sections into **ESC/POS** (Escape Sequence for Point o
150
150
  - ✅ **Linux**: Fully functional (CUPS)
151
151
  - ✅ **macOS**: Fully functional (CUPS)
152
152
  - ✅ **Windows**: Fully functional (WinAPI)
153
- - ✅ **Android**: Bluetooth and USB printer discovery and printing
153
+ - ✅ **Android**: Bluetooth, USB, and Network printer discovery and printing
154
154
  - ❌ **iOS**: Not implemented
155
155
 
156
156
  ### Supported Connections
157
157
 
158
158
  | Connection | Linux | macOS | Windows | Android |
159
159
  | ---------- | ----- | ----- | ------- | ------- |
160
- | USB | ✅ | ✅ | ✅ | ✅ (discovery only) |
161
- | Network | ✅ | ✅ | ✅ | |
160
+ | USB | ✅ | ✅ | ✅ | ✅ |
161
+ | Network | ✅ | ✅ | ✅ | |
162
162
  | Bluetooth | ❌ | ❌ | ❌ | ✅ |
163
163
 
164
- > **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.
164
+ > **Android note**: The `printer` field in `PrintJobRequest` must be the printer identifier returned by `list_thermal_printers`. For Bluetooth, it's the MAC address (e.g. `"AA:BB:CC:DD:EE:FF"`). For USB, it's `"VID:xxxx/PID:yyyy"`. For Network, it's `"IP:PORT"` (e.g. `"192.168.1.100:9100"`). Required permissions (Bluetooth, USB, Internet) are handled automatically at runtime.
165
165
 
166
166
  ## Installation
167
167
 
@@ -285,7 +285,7 @@ try { await test_thermal_printer({
285
285
  "beep": true,
286
286
  "open_cash_drawer": false,
287
287
  "code_page": {
288
- "codepage": 6,
288
+ "code_page": 6,
289
289
  "encode": ENCODE.WINDOWS_1252,
290
290
  "use_gbk": false
291
291
  }
@@ -356,7 +356,7 @@ try { await print_thermal_printer({
356
356
  "beep": false,
357
357
  "open_cash_drawer": false,
358
358
  "code_page": {
359
- "codepage": 6,
359
+ "code_page": 6,
360
360
  "encode": ENCODE.WINDOWS_1252,
361
361
  "use_gbk": false
362
362
  }
@@ -391,12 +391,14 @@ Returns `Promise<void>`. Resolves when printing completes successfully. **Throws
391
391
  | `printer` | string | ✅ Yes | Printer name |
392
392
  | `paper_size` | PaperSize | ❌ No | Paper size (default: `"Mm80"`) — see [Paper Sizes](#paper-sizes) |
393
393
  | `options` | PrinterOptions | ❌ No | Configuration 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`) |
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
397
  | `options.code_page` | CodePage | ✅ Yes | Required ESC/POS page selection plus host-side encoding strategy — see [CodePage](#codepage) |
398
398
  | `sections` | array | ✅ Yes | Array of sections to print (see [Section Types](#section-types)) |
399
399
 
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
+
400
402
  #### Paper Sizes
401
403
 
402
404
  | Value | Paper width | Chars/line | Typical use |
@@ -891,7 +893,7 @@ The plugin exports typed constants and builder functions so you never have to ty
891
893
 
892
894
  Set the character encoding once in `PrinterOptions.code_page` and all text sections (`Title`, `Subtitle`, `Text`, `Table`) will use it automatically.
893
895
 
894
- Each printer model assigns its own `ESC t n` values, so `CodePage.codepage` accepts the raw page number directly. `CodePage.encode` controls the host-side encoding used before bytes are sent to the printer. `CodePage.use_gbk` explicitly controls whether characters that the selected `encode` cannot represent should be retried with GBK before falling back to the original UTF-8 bytes.
896
+ Each printer model assigns its own `ESC t n` values, so `CodePage.code_page` accepts the raw page number directly. `CodePage.encode` controls the host-side encoding used before bytes are sent to the printer. `CodePage.use_gbk` explicitly controls whether characters that the selected `encode` cannot represent should be retried with GBK before falling back to the original UTF-8 bytes.
895
897
 
896
898
  ```typescript
897
899
  import { ENCODE, type CodePage } from "tauri-plugin-thermal-printer";
@@ -901,7 +903,7 @@ const options = {
901
903
  beep: false,
902
904
  open_cash_drawer: false,
903
905
  code_page: {
904
- codepage: 6,
906
+ code_page: 6,
905
907
  encode: ENCODE.WINDOWS_1252,
906
908
  use_gbk: false,
907
909
  }, // sends ESC t 6
@@ -912,7 +914,7 @@ const options = {
912
914
 
913
915
  | Field | Required | Description |
914
916
  |---|---|---|
915
- | `codepage` | ✅ Yes | Raw `ESC t n` value sent to the printer. |
917
+ | `code_page` | ✅ Yes | Raw `ESC t n` value sent to the printer. |
916
918
  | `encode` | ❌ No | Host-side encoding strategy. Defaults to `ENCODE.ACCENT_REMOVER`. |
917
919
  | `use_gbk` | ❌ No | Retries GBK for characters that `encode` cannot represent before falling back to the original UTF-8 bytes. Defaults to `false`. |
918
920
 
@@ -1072,7 +1074,7 @@ const job: PrintJobRequest = {
1072
1074
  beep: false,
1073
1075
  open_cash_drawer: false,
1074
1076
  code_page: {
1075
- codepage: 6,
1077
+ code_page: 6,
1076
1078
  encode: ENCODE.WINDOWS_1252,
1077
1079
  use_gbk: false,
1078
1080
  },
@@ -1144,7 +1146,7 @@ await print_thermal_printer(job);
1144
1146
 
1145
1147
  This section contains practical examples for different use cases. Each example demonstrates how to structure print jobs for various business scenarios.
1146
1148
 
1147
- > **NOTE:** Paper is automatically cut at the end of printing with a full cut. You don't need to add a `Cut` section manually unless you want a specific partial cut.
1149
+ > **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
1150
 
1149
1151
  ### 🛒 Long Receipt (Supermarket - 80mm)
1150
1152
 
@@ -1625,5 +1627,6 @@ const paymentReceipt: PrintJobRequest = {
1625
1627
  - No need to manually reset styles
1626
1628
 
1627
1629
  #### Paper Cutting
1628
- - **Automatic**: Paper is automatically cut at the end with a full cut
1629
- - **Manual** (optional): Add a `Cut` section if you need a specific partial cut
1630
+ - **Automatic**: `options.cut_paper = true` appends a tail `Cut` section with `mode: "partial"` and `feed: 0`
1631
+ - **Manual**: Add a `Cut` section anywhere in `sections` to issue explicit cut commands
1632
+ - **Combined**: Automatic and manual cuts are both emitted when both are present
@@ -17,7 +17,7 @@ export declare function getPaperSizePixelsWidth(paperSize: PaperSize): number;
17
17
  * to GBK. It defaults to `false`.
18
18
  */
19
19
  export interface CodePage {
20
- codepage: number;
20
+ code_page: number;
21
21
  encode?: Encode;
22
22
  use_gbk?: boolean;
23
23
  }
@@ -93,8 +93,11 @@ export declare const CUT_MODE: {
93
93
  readonly PARTIAL: CutMode;
94
94
  };
95
95
  export interface PrinterOptions {
96
+ /** Append a tail `Cut` section with mode `"partial"` and feed `0`. */
96
97
  cut_paper: boolean;
98
+ /** Append a tail `Beep` section with times `1` and duration `3`. */
97
99
  beep: boolean;
100
+ /** Append a tail `Drawer` section with pin `2` and pulse time `100`. */
98
101
  open_cash_drawer: boolean;
99
102
  /** Required ESC/POS page plus host-side encoding strategy. */
100
103
  code_page: CodePage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-thermal-printer",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "author": "luis3132",
5
5
  "description": "Plugin for Tauri to send esc/pos commands to thermal_printer",
6
6
  "type": "module",