tauri-plugin-thermal-printer 1.2.2 → 1.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Luis Andres Gonzalez Corzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -881,29 +881,23 @@ The plugin exports typed constants and builder functions so you never have to ty
881
881
 
882
882
  Set the character encoding once in `PrinterOptions.code_page` and all text sections (`Title`, `Subtitle`, `Text`, `Table`) will use it automatically.
883
883
 
884
+ Each printer model assigns its own numbers to code pages, so `CodePage` accepts the raw page number directly via `codePage(n)`. Check your printer's manual for the correct value.
885
+
884
886
  ```typescript
885
- import { CODE_PAGE, type CodePage } from "tauri-plugin-thermal-printer";
887
+ import { codePage, CODE_PAGE, type CodePage } from "tauri-plugin-thermal-printer";
886
888
 
887
- // In your PrintJobRequest:
888
889
  const options = {
889
890
  cut_paper: true,
890
891
  beep: false,
891
892
  open_cash_drawer: false,
892
- code_page: CODE_PAGE.SPANISH, // enables á é í ó ú ñ ü ¿ ¡
893
+ code_page: codePage(2), // sends ESC t 2 CP850 on most Epson-compatible printers
893
894
  };
894
895
  ```
895
896
 
896
- | Constant | Value | Code Page | Languages |
897
- |---|---|---|---|
898
- | `CODE_PAGE.DEFAULT` | `"Default"` | CP437 | ASCII only no accented characters |
899
- | `CODE_PAGE.SPANISH` | `"Spanish"` | CP850 | **Spanish**, French, Italian, German, Portuguese |
900
- | `CODE_PAGE.FRENCH` | `"French"` | CP850 | Alias of Spanish |
901
- | `CODE_PAGE.PORTUGUESE` | `"Portuguese"` | CP860 | **Portuguese** (ã, õ) |
902
- | `CODE_PAGE.CANADIAN_FRENCH` | `"CanadianFrench"` | CP863 | Canadian French |
903
- | `CODE_PAGE.NORDIC` | `"Nordic"` | CP865 | Swedish, Norwegian, Danish, Finnish (å, ø, æ) |
904
- | `CODE_PAGE.WINDOWS_LATIN` | `"WindowsLatin"` | CP1252 | Wide Western European — includes € |
905
- | `CODE_PAGE.RUSSIAN` | `"Russian"` | CP866 | **Russian** / Cyrillic |
906
- | `CODE_PAGE.EASTERN_EUROPE` | `"EasternEurope"` | CP852 | **Polish**, Czech, Slovak, Hungarian |
897
+ | Value | Description |
898
+ |---|---|
899
+ | `codePage(n)` | Sends `ESC t n` with the given number. The user is responsible for choosing the correct value for their printer model. |
900
+ | `CODE_PAGE.ACCENT_REMOVER` | Removes accents and special characters by converting them to their ASCII equivalents (á→a, ß→ss, ¿→?, €→EUR). Useful when printers do not support alternative code pages. |
907
901
 
908
902
  > **Note**: Without a `code_page`, accented characters (á, ñ, ü, etc.) will print as `?`. Set it once in `options` and it applies to the entire document.
909
903
 
package/dist-js/index.cjs CHANGED
@@ -25,6 +25,10 @@ function getPaperSizeCharsPerLine(paperSize) {
25
25
  function getPaperSizePixelsWidth(paperSize) {
26
26
  return PAPER_SIZE_PIXELS_WIDTH[paperSize];
27
27
  }
28
+ /** Creates a `CodePage` that sends the given ESC/POS code page number. */
29
+ function codePage(n) {
30
+ return { Page: n };
31
+ }
28
32
  // ─── Convenience style presets ────────────────────────────────────────────────
29
33
  const TEXT_ALIGN = {
30
34
  LEFT: 'left',
@@ -80,24 +84,6 @@ const CUT_MODE = {
80
84
  PARTIAL: 'partial',
81
85
  };
82
86
  const CODE_PAGE = {
83
- /** CP437 — ASCII only, no accented characters */
84
- DEFAULT: 'Default',
85
- /** CP850 — Spanish, French, Italian, German */
86
- SPANISH: 'Spanish',
87
- /** CP850 — Alias of Spanish */
88
- FRENCH: 'French',
89
- /** CP860 — Portuguese (ã, õ) */
90
- PORTUGUESE: 'Portuguese',
91
- /** CP863 — Canadian French */
92
- CANADIAN_FRENCH: 'CanadianFrench',
93
- /** CP865 — Nordic languages (å, ø, æ) */
94
- NORDIC: 'Nordic',
95
- /** CP1252 — Wide Western European, includes € */
96
- WINDOWS_LATIN: 'WindowsLatin',
97
- /** CP866 — Russian / Cyrillic */
98
- RUSSIAN: 'Russian',
99
- /** CP852 — Eastern Europe (Polish, Czech, Slovak, Hungarian) */
100
- EASTERN_EUROPE: 'EasternEurope',
101
87
  /** Strips accents and special chars to plain ASCII. Use when the printer
102
88
  * ignores ESC t commands. á→a, é→e, ñ→n, ß→ss, ¿→?, €→EUR, etc. */
103
89
  ACCENT_REMOVER: 'AccentRemover',
@@ -260,6 +246,7 @@ exports.TEXT_FONT = TEXT_FONT;
260
246
  exports.TEXT_SIZE = TEXT_SIZE;
261
247
  exports.barcode = barcode;
262
248
  exports.beep = beep;
249
+ exports.codePage = codePage;
263
250
  exports.cut = cut;
264
251
  exports.dataMatrix = dataMatrix;
265
252
  exports.drawer = drawer;
@@ -6,21 +6,19 @@ export declare function getPaperSizeCharsPerLine(paperSize: PaperSize): number;
6
6
  export declare function getPaperSizePixelsWidth(paperSize: PaperSize): number;
7
7
  /**
8
8
  * Character encoding page to use for printing.
9
- * Select by language/region — no need to know ESC/POS code page numbers.
10
9
  *
11
- * | Value | Code Page | Languages |
12
- * |-----------------|-----------|------------------------------------------------|
13
- * | Default | CP437 | ASCII only — no accented characters |
14
- * | Spanish | CP850 | Spanish, French, Italian, German, Portuguese |
15
- * | French | CP850 | Alias of Spanish |
16
- * | Portuguese | CP860 | Portuguese (includes ã, õ) |
17
- * | CanadianFrench | CP863 | Canadian French |
18
- * | Nordic | CP865 | Swedish, Norwegian, Danish, Finnish (å, ø, æ) |
19
- * | WindowsLatin | CP1252 | Wide Western European coverage (includes €) |
20
- * | Russian | CP866 | Russian / Cyrillic |
21
- * | EasternEurope | CP852 | Polish, Czech, Slovak, Hungarian |
10
+ * - `{ Page: n }` — sends `ESC t n` to the printer; the user is responsible
11
+ * for choosing the correct number for their printer model and ensuring the
12
+ * text is already encoded accordingly.
13
+ * - `"AccentRemover"` strips accents/diacritics to plain ASCII before
14
+ * sending. Use when the printer ignores `ESC t` or has no alternate code
15
+ * page. Examples: á→a, é→e, ñ→n, ß→ss, ¿→?, €→EUR.
22
16
  */
23
- export type CodePage = 'Default' | 'Spanish' | 'French' | 'Portuguese' | 'CanadianFrench' | 'Nordic' | 'WindowsLatin' | 'Russian' | 'EasternEurope' | 'AccentRemover';
17
+ export type CodePage = {
18
+ Page: number;
19
+ } | 'AccentRemover';
20
+ /** Creates a `CodePage` that sends the given ESC/POS code page number. */
21
+ export declare function codePage(n: number): CodePage;
24
22
  /** Text alignment options */
25
23
  export type TextAlign = 'left' | 'center' | 'right';
26
24
  /** Text size options */
@@ -93,24 +91,6 @@ export declare const CUT_MODE: {
93
91
  readonly PARTIAL: CutMode;
94
92
  };
95
93
  export declare const CODE_PAGE: {
96
- /** CP437 — ASCII only, no accented characters */
97
- readonly DEFAULT: CodePage;
98
- /** CP850 — Spanish, French, Italian, German */
99
- readonly SPANISH: CodePage;
100
- /** CP850 — Alias of Spanish */
101
- readonly FRENCH: CodePage;
102
- /** CP860 — Portuguese (ã, õ) */
103
- readonly PORTUGUESE: CodePage;
104
- /** CP863 — Canadian French */
105
- readonly CANADIAN_FRENCH: CodePage;
106
- /** CP865 — Nordic languages (å, ø, æ) */
107
- readonly NORDIC: CodePage;
108
- /** CP1252 — Wide Western European, includes € */
109
- readonly WINDOWS_LATIN: CodePage;
110
- /** CP866 — Russian / Cyrillic */
111
- readonly RUSSIAN: CodePage;
112
- /** CP852 — Eastern Europe (Polish, Czech, Slovak, Hungarian) */
113
- readonly EASTERN_EUROPE: CodePage;
114
94
  /** Strips accents and special chars to plain ASCII. Use when the printer
115
95
  * ignores ESC t commands. á→a, é→e, ñ→n, ß→ss, ¿→?, €→EUR, etc. */
116
96
  readonly ACCENT_REMOVER: CodePage;
@@ -119,7 +99,7 @@ export interface PrinterOptions {
119
99
  cut_paper: boolean;
120
100
  beep: boolean;
121
101
  open_cash_drawer: boolean;
122
- /** Character encoding for the printer. Default: 'Default' (ASCII only). */
102
+ /** Character encoding for the printer. Default: `{ Page: 0 }` (CP437, ASCII only). */
123
103
  code_page?: CodePage;
124
104
  }
125
105
  export interface GlobalStyles {
package/dist-js/index.js CHANGED
@@ -23,6 +23,10 @@ function getPaperSizeCharsPerLine(paperSize) {
23
23
  function getPaperSizePixelsWidth(paperSize) {
24
24
  return PAPER_SIZE_PIXELS_WIDTH[paperSize];
25
25
  }
26
+ /** Creates a `CodePage` that sends the given ESC/POS code page number. */
27
+ function codePage(n) {
28
+ return { Page: n };
29
+ }
26
30
  // ─── Convenience style presets ────────────────────────────────────────────────
27
31
  const TEXT_ALIGN = {
28
32
  LEFT: 'left',
@@ -78,24 +82,6 @@ const CUT_MODE = {
78
82
  PARTIAL: 'partial',
79
83
  };
80
84
  const CODE_PAGE = {
81
- /** CP437 — ASCII only, no accented characters */
82
- DEFAULT: 'Default',
83
- /** CP850 — Spanish, French, Italian, German */
84
- SPANISH: 'Spanish',
85
- /** CP850 — Alias of Spanish */
86
- FRENCH: 'French',
87
- /** CP860 — Portuguese (ã, õ) */
88
- PORTUGUESE: 'Portuguese',
89
- /** CP863 — Canadian French */
90
- CANADIAN_FRENCH: 'CanadianFrench',
91
- /** CP865 — Nordic languages (å, ø, æ) */
92
- NORDIC: 'Nordic',
93
- /** CP1252 — Wide Western European, includes € */
94
- WINDOWS_LATIN: 'WindowsLatin',
95
- /** CP866 — Russian / Cyrillic */
96
- RUSSIAN: 'Russian',
97
- /** CP852 — Eastern Europe (Polish, Czech, Slovak, Hungarian) */
98
- EASTERN_EUROPE: 'EasternEurope',
99
85
  /** Strips accents and special chars to plain ASCII. Use when the printer
100
86
  * ignores ESC t commands. á→a, é→e, ñ→n, ß→ss, ¿→?, €→EUR, etc. */
101
87
  ACCENT_REMOVER: 'AccentRemover',
@@ -244,4 +230,4 @@ async function test_thermal_printer(testPrintRequest) {
244
230
  });
245
231
  }
246
232
 
247
- export { BARCODE_TEXT_POSITION, BARCODE_TYPE, CODE_PAGE, CUT_MODE, DEFAULT_PAPER_SIZE, IMAGE_MODE, PAPER_SIZE_CHARS_PER_LINE, PAPER_SIZE_PIXELS_WIDTH, QR_ERROR_CORRECTION, TEXT_ALIGN, TEXT_FONT, TEXT_SIZE, barcode, beep, cut, dataMatrix, drawer, feed, getPaperSizeCharsPerLine, getPaperSizePixelsWidth, globalStyles, image, line, list_thermal_printers, logo, pdf417, print_thermal_printer, qr, subtitle, table, test_thermal_printer, text, title };
233
+ export { BARCODE_TEXT_POSITION, BARCODE_TYPE, CODE_PAGE, CUT_MODE, DEFAULT_PAPER_SIZE, IMAGE_MODE, PAPER_SIZE_CHARS_PER_LINE, PAPER_SIZE_PIXELS_WIDTH, QR_ERROR_CORRECTION, TEXT_ALIGN, TEXT_FONT, TEXT_SIZE, barcode, beep, codePage, cut, dataMatrix, drawer, feed, getPaperSizeCharsPerLine, getPaperSizePixelsWidth, globalStyles, image, line, list_thermal_printers, logo, pdf417, print_thermal_printer, qr, subtitle, table, test_thermal_printer, text, title };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-thermal-printer",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "author": "luis3132",
5
5
  "description": "Plugin for Tauri to send esc/pos commands to thermal_printer",
6
6
  "type": "module",