tauri-plugin-thermal-printer 1.1.0 → 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 +21 -0
- package/README.md +395 -54
- package/dist-js/index.cjs +250 -3
- package/dist-js/index.d.ts +202 -18
- package/dist-js/index.js +220 -4
- package/package.json +2 -2
package/dist-js/index.cjs
CHANGED
|
@@ -2,20 +2,267 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@tauri-apps/api/core');
|
|
4
4
|
|
|
5
|
+
const PAPER_SIZE_CHARS_PER_LINE = {
|
|
6
|
+
Mm40: 21,
|
|
7
|
+
Mm44: 24,
|
|
8
|
+
Mm58: 32,
|
|
9
|
+
Mm72: 42,
|
|
10
|
+
Mm80: 48,
|
|
11
|
+
Mm104: 62,
|
|
12
|
+
};
|
|
13
|
+
const PAPER_SIZE_PIXELS_WIDTH = {
|
|
14
|
+
Mm40: 256,
|
|
15
|
+
Mm44: 288,
|
|
16
|
+
Mm58: 384,
|
|
17
|
+
Mm72: 512,
|
|
18
|
+
Mm80: 576,
|
|
19
|
+
Mm104: 752,
|
|
20
|
+
};
|
|
21
|
+
const DEFAULT_PAPER_SIZE = 'Mm80';
|
|
22
|
+
function getPaperSizeCharsPerLine(paperSize) {
|
|
23
|
+
return PAPER_SIZE_CHARS_PER_LINE[paperSize];
|
|
24
|
+
}
|
|
25
|
+
function getPaperSizePixelsWidth(paperSize) {
|
|
26
|
+
return PAPER_SIZE_PIXELS_WIDTH[paperSize];
|
|
27
|
+
}
|
|
28
|
+
/** Creates a `CodePage` that sends the given ESC/POS code page number. */
|
|
29
|
+
function codePage(n) {
|
|
30
|
+
return { Page: n };
|
|
31
|
+
}
|
|
32
|
+
// ─── Convenience style presets ────────────────────────────────────────────────
|
|
33
|
+
const TEXT_ALIGN = {
|
|
34
|
+
LEFT: 'left',
|
|
35
|
+
CENTER: 'center',
|
|
36
|
+
RIGHT: 'right',
|
|
37
|
+
};
|
|
38
|
+
const TEXT_SIZE = {
|
|
39
|
+
NORMAL: 'normal',
|
|
40
|
+
HEIGHT: 'height',
|
|
41
|
+
WIDTH: 'width',
|
|
42
|
+
DOUBLE: 'double',
|
|
43
|
+
};
|
|
44
|
+
const TEXT_FONT = {
|
|
45
|
+
A: 'A',
|
|
46
|
+
B: 'B',
|
|
47
|
+
C: 'C',
|
|
48
|
+
};
|
|
49
|
+
const BARCODE_TYPE = {
|
|
50
|
+
UPC_A: 'UPC-A',
|
|
51
|
+
UPC_E: 'UPC-E',
|
|
52
|
+
EAN13: 'EAN13',
|
|
53
|
+
EAN8: 'EAN8',
|
|
54
|
+
CODE39: 'CODE39',
|
|
55
|
+
ITF: 'ITF',
|
|
56
|
+
CODABAR: 'CODABAR',
|
|
57
|
+
CODE93: 'CODE93',
|
|
58
|
+
CODE128: 'CODE128',
|
|
59
|
+
};
|
|
60
|
+
const BARCODE_TEXT_POSITION = {
|
|
61
|
+
NONE: 'none',
|
|
62
|
+
ABOVE: 'above',
|
|
63
|
+
BELOW: 'below',
|
|
64
|
+
BOTH: 'both',
|
|
65
|
+
};
|
|
66
|
+
const QR_ERROR_CORRECTION = {
|
|
67
|
+
/** Low — 7% recovery */
|
|
68
|
+
L: 'L',
|
|
69
|
+
/** Medium — 15% recovery (recommended default) */
|
|
70
|
+
M: 'M',
|
|
71
|
+
/** Quartile — 25% recovery */
|
|
72
|
+
Q: 'Q',
|
|
73
|
+
/** High — 30% recovery */
|
|
74
|
+
H: 'H',
|
|
75
|
+
};
|
|
76
|
+
const IMAGE_MODE = {
|
|
77
|
+
NORMAL: 'normal',
|
|
78
|
+
DOUBLE_WIDTH: 'double_width',
|
|
79
|
+
DOUBLE_HEIGHT: 'double_height',
|
|
80
|
+
QUADRUPLE: 'quadruple',
|
|
81
|
+
};
|
|
82
|
+
const CUT_MODE = {
|
|
83
|
+
FULL: 'full',
|
|
84
|
+
PARTIAL: 'partial',
|
|
85
|
+
};
|
|
86
|
+
const CODE_PAGE = {
|
|
87
|
+
/** Strips accents and special chars to plain ASCII. Use when the printer
|
|
88
|
+
* ignores ESC t commands. á→a, é→e, ñ→n, ß→ss, ¿→?, €→EUR, etc. */
|
|
89
|
+
ACCENT_REMOVER: 'AccentRemover',
|
|
90
|
+
};
|
|
91
|
+
// ─── Helper builders ──────────────────────────────────────────────────────────
|
|
92
|
+
/** Creates a Title section */
|
|
93
|
+
function title(text, styles) {
|
|
94
|
+
return { Title: { text, styles } };
|
|
95
|
+
}
|
|
96
|
+
/** Creates a Subtitle section */
|
|
97
|
+
function subtitle(text, styles) {
|
|
98
|
+
return { Subtitle: { text, styles } };
|
|
99
|
+
}
|
|
100
|
+
/** Creates a Text section */
|
|
101
|
+
function text(text, styles) {
|
|
102
|
+
return { Text: { text, styles } };
|
|
103
|
+
}
|
|
104
|
+
/** Creates a Line separator section */
|
|
105
|
+
function line(character = '-') {
|
|
106
|
+
return { Line: { character } };
|
|
107
|
+
}
|
|
108
|
+
/** Creates a Feed section */
|
|
109
|
+
function feed(value, feed_type = 'lines') {
|
|
110
|
+
return { Feed: { feed_type, value } };
|
|
111
|
+
}
|
|
112
|
+
/** Creates a Cut section */
|
|
113
|
+
function cut(mode = 'partial', feedLines = 4) {
|
|
114
|
+
return { Cut: { mode, feed: feedLines } };
|
|
115
|
+
}
|
|
116
|
+
/** Creates a GlobalStyles section — affects all subsequent sections until changed */
|
|
117
|
+
function globalStyles(styles) {
|
|
118
|
+
return { GlobalStyles: styles };
|
|
119
|
+
}
|
|
120
|
+
/** Creates a Beep section */
|
|
121
|
+
function beep(times = 1, duration = 3) {
|
|
122
|
+
return { Beep: { times, duration } };
|
|
123
|
+
}
|
|
124
|
+
/** Creates a Drawer section */
|
|
125
|
+
function drawer(pin = 2, pulse_time = 120) {
|
|
126
|
+
return { Drawer: { pin, pulse_time } };
|
|
127
|
+
}
|
|
128
|
+
/** Creates a Table section */
|
|
129
|
+
function table(columns, body, options) {
|
|
130
|
+
return {
|
|
131
|
+
Table: {
|
|
132
|
+
columns,
|
|
133
|
+
body,
|
|
134
|
+
column_widths: options?.column_widths,
|
|
135
|
+
header: options?.header,
|
|
136
|
+
truncate: options?.truncate ?? true,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** Creates a QR section */
|
|
141
|
+
function qr(data, options) {
|
|
142
|
+
return {
|
|
143
|
+
Qr: {
|
|
144
|
+
data,
|
|
145
|
+
size: options?.size ?? 6,
|
|
146
|
+
error_correction: options?.error_correction ?? 'M',
|
|
147
|
+
model: options?.model ?? 2,
|
|
148
|
+
align: options?.align,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** Creates a Barcode section */
|
|
153
|
+
function barcode(data, barcode_type = 'CODE128', options) {
|
|
154
|
+
return {
|
|
155
|
+
Barcode: {
|
|
156
|
+
data,
|
|
157
|
+
barcode_type,
|
|
158
|
+
width: options?.width ?? 3,
|
|
159
|
+
height: options?.height ?? 80,
|
|
160
|
+
text_position: options?.text_position ?? 'below',
|
|
161
|
+
align: options?.align,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Creates a DataMatrix section */
|
|
166
|
+
function dataMatrix(data, size = 6) {
|
|
167
|
+
return {
|
|
168
|
+
DataMatrix: {
|
|
169
|
+
data,
|
|
170
|
+
size,
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** Creates a PDF417 section */
|
|
175
|
+
function pdf417(data, options) {
|
|
176
|
+
return {
|
|
177
|
+
Pdf417: {
|
|
178
|
+
data,
|
|
179
|
+
columns: options?.columns ?? 0,
|
|
180
|
+
rows: options?.rows ?? 0,
|
|
181
|
+
width: options?.width ?? 2,
|
|
182
|
+
height: options?.height ?? 3,
|
|
183
|
+
error_correction: options?.error_correction ?? 2,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** Creates an Image section */
|
|
188
|
+
function image(data, options) {
|
|
189
|
+
return {
|
|
190
|
+
Image: {
|
|
191
|
+
data,
|
|
192
|
+
max_width: options?.max_width ?? 0,
|
|
193
|
+
align: options?.align ?? 'center',
|
|
194
|
+
dithering: options?.dithering ?? true,
|
|
195
|
+
size: options?.size ?? 'normal',
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** Creates a Logo section */
|
|
200
|
+
function logo(key_code, mode = 'normal') {
|
|
201
|
+
return {
|
|
202
|
+
Logo: {
|
|
203
|
+
key_code,
|
|
204
|
+
mode,
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
// ─── Commands ─────────────────────────────────────────────────────────────────
|
|
209
|
+
/**
|
|
210
|
+
* Sends a print job to the specified thermal printer.
|
|
211
|
+
* @throws {string} Error message from the printer or document generation if the job fails.
|
|
212
|
+
*/
|
|
5
213
|
async function print_thermal_printer(printJobRequest) {
|
|
6
|
-
|
|
7
|
-
printJobRequest
|
|
214
|
+
await core.invoke('plugin:thermal-printer|print_thermal_printer', {
|
|
215
|
+
printJobRequest,
|
|
8
216
|
});
|
|
9
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns the list of available thermal printers on the current system.
|
|
220
|
+
* @throws {string} Error message if printer enumeration fails.
|
|
221
|
+
*/
|
|
10
222
|
async function list_thermal_printers() {
|
|
11
223
|
return await core.invoke('plugin:thermal-printer|list_thermal_printers');
|
|
12
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Sends a test print job to verify the printer is working correctly.
|
|
227
|
+
* @throws {string} Error message from the printer or document generation if the job fails.
|
|
228
|
+
*/
|
|
13
229
|
async function test_thermal_printer(testPrintRequest) {
|
|
14
|
-
|
|
230
|
+
await core.invoke('plugin:thermal-printer|test_thermal_printer', {
|
|
15
231
|
printTestRequest: testPrintRequest,
|
|
16
232
|
});
|
|
17
233
|
}
|
|
18
234
|
|
|
235
|
+
exports.BARCODE_TEXT_POSITION = BARCODE_TEXT_POSITION;
|
|
236
|
+
exports.BARCODE_TYPE = BARCODE_TYPE;
|
|
237
|
+
exports.CODE_PAGE = CODE_PAGE;
|
|
238
|
+
exports.CUT_MODE = CUT_MODE;
|
|
239
|
+
exports.DEFAULT_PAPER_SIZE = DEFAULT_PAPER_SIZE;
|
|
240
|
+
exports.IMAGE_MODE = IMAGE_MODE;
|
|
241
|
+
exports.PAPER_SIZE_CHARS_PER_LINE = PAPER_SIZE_CHARS_PER_LINE;
|
|
242
|
+
exports.PAPER_SIZE_PIXELS_WIDTH = PAPER_SIZE_PIXELS_WIDTH;
|
|
243
|
+
exports.QR_ERROR_CORRECTION = QR_ERROR_CORRECTION;
|
|
244
|
+
exports.TEXT_ALIGN = TEXT_ALIGN;
|
|
245
|
+
exports.TEXT_FONT = TEXT_FONT;
|
|
246
|
+
exports.TEXT_SIZE = TEXT_SIZE;
|
|
247
|
+
exports.barcode = barcode;
|
|
248
|
+
exports.beep = beep;
|
|
249
|
+
exports.codePage = codePage;
|
|
250
|
+
exports.cut = cut;
|
|
251
|
+
exports.dataMatrix = dataMatrix;
|
|
252
|
+
exports.drawer = drawer;
|
|
253
|
+
exports.feed = feed;
|
|
254
|
+
exports.getPaperSizeCharsPerLine = getPaperSizeCharsPerLine;
|
|
255
|
+
exports.getPaperSizePixelsWidth = getPaperSizePixelsWidth;
|
|
256
|
+
exports.globalStyles = globalStyles;
|
|
257
|
+
exports.image = image;
|
|
258
|
+
exports.line = line;
|
|
19
259
|
exports.list_thermal_printers = list_thermal_printers;
|
|
260
|
+
exports.logo = logo;
|
|
261
|
+
exports.pdf417 = pdf417;
|
|
20
262
|
exports.print_thermal_printer = print_thermal_printer;
|
|
263
|
+
exports.qr = qr;
|
|
264
|
+
exports.subtitle = subtitle;
|
|
265
|
+
exports.table = table;
|
|
21
266
|
exports.test_thermal_printer = test_thermal_printer;
|
|
267
|
+
exports.text = text;
|
|
268
|
+
exports.title = title;
|
package/dist-js/index.d.ts
CHANGED
|
@@ -1,19 +1,117 @@
|
|
|
1
|
-
export type PaperSize = 'Mm58' | 'Mm80';
|
|
1
|
+
export type PaperSize = 'Mm40' | 'Mm44' | 'Mm58' | 'Mm72' | 'Mm80' | 'Mm104';
|
|
2
|
+
export declare const PAPER_SIZE_CHARS_PER_LINE: Record<PaperSize, number>;
|
|
3
|
+
export declare const PAPER_SIZE_PIXELS_WIDTH: Record<PaperSize, number>;
|
|
4
|
+
export declare const DEFAULT_PAPER_SIZE: PaperSize;
|
|
5
|
+
export declare function getPaperSizeCharsPerLine(paperSize: PaperSize): number;
|
|
6
|
+
export declare function getPaperSizePixelsWidth(paperSize: PaperSize): number;
|
|
7
|
+
/**
|
|
8
|
+
* Character encoding page to use for printing.
|
|
9
|
+
*
|
|
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.
|
|
16
|
+
*/
|
|
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;
|
|
22
|
+
/** Text alignment options */
|
|
23
|
+
export type TextAlign = 'left' | 'center' | 'right';
|
|
24
|
+
/** Text size options */
|
|
25
|
+
export type TextSize = 'normal' | 'height' | 'width' | 'double';
|
|
26
|
+
/** Font options */
|
|
27
|
+
export type TextFont = 'A' | 'B' | 'C';
|
|
28
|
+
/** Barcode text position options */
|
|
29
|
+
export type BarcodeTextPosition = 'none' | 'above' | 'below' | 'both';
|
|
30
|
+
/** Barcode type options */
|
|
31
|
+
export type BarcodeType = 'UPC-A' | 'UPC-E' | 'EAN13' | 'EAN8' | 'CODE39' | 'ITF' | 'CODABAR' | 'CODE93' | 'CODE128';
|
|
32
|
+
/** QR error correction level */
|
|
33
|
+
export type QrErrorCorrection = 'L' | 'M' | 'Q' | 'H';
|
|
34
|
+
/** Image size mode */
|
|
35
|
+
export type ImageMode = 'normal' | 'double_width' | 'double_height' | 'quadruple';
|
|
36
|
+
/** Feed type */
|
|
37
|
+
export type FeedType = 'lines' | 'dots' | 'line_feed';
|
|
38
|
+
/** Cut mode */
|
|
39
|
+
export type CutMode = 'full' | 'partial' | 'partial_alt' | 'partial_alt2';
|
|
40
|
+
export declare const TEXT_ALIGN: {
|
|
41
|
+
readonly LEFT: TextAlign;
|
|
42
|
+
readonly CENTER: TextAlign;
|
|
43
|
+
readonly RIGHT: TextAlign;
|
|
44
|
+
};
|
|
45
|
+
export declare const TEXT_SIZE: {
|
|
46
|
+
readonly NORMAL: TextSize;
|
|
47
|
+
readonly HEIGHT: TextSize;
|
|
48
|
+
readonly WIDTH: TextSize;
|
|
49
|
+
readonly DOUBLE: TextSize;
|
|
50
|
+
};
|
|
51
|
+
export declare const TEXT_FONT: {
|
|
52
|
+
readonly A: TextFont;
|
|
53
|
+
readonly B: TextFont;
|
|
54
|
+
readonly C: TextFont;
|
|
55
|
+
};
|
|
56
|
+
export declare const BARCODE_TYPE: {
|
|
57
|
+
readonly UPC_A: BarcodeType;
|
|
58
|
+
readonly UPC_E: BarcodeType;
|
|
59
|
+
readonly EAN13: BarcodeType;
|
|
60
|
+
readonly EAN8: BarcodeType;
|
|
61
|
+
readonly CODE39: BarcodeType;
|
|
62
|
+
readonly ITF: BarcodeType;
|
|
63
|
+
readonly CODABAR: BarcodeType;
|
|
64
|
+
readonly CODE93: BarcodeType;
|
|
65
|
+
readonly CODE128: BarcodeType;
|
|
66
|
+
};
|
|
67
|
+
export declare const BARCODE_TEXT_POSITION: {
|
|
68
|
+
readonly NONE: BarcodeTextPosition;
|
|
69
|
+
readonly ABOVE: BarcodeTextPosition;
|
|
70
|
+
readonly BELOW: BarcodeTextPosition;
|
|
71
|
+
readonly BOTH: BarcodeTextPosition;
|
|
72
|
+
};
|
|
73
|
+
export declare const QR_ERROR_CORRECTION: {
|
|
74
|
+
/** Low — 7% recovery */
|
|
75
|
+
readonly L: QrErrorCorrection;
|
|
76
|
+
/** Medium — 15% recovery (recommended default) */
|
|
77
|
+
readonly M: QrErrorCorrection;
|
|
78
|
+
/** Quartile — 25% recovery */
|
|
79
|
+
readonly Q: QrErrorCorrection;
|
|
80
|
+
/** High — 30% recovery */
|
|
81
|
+
readonly H: QrErrorCorrection;
|
|
82
|
+
};
|
|
83
|
+
export declare const IMAGE_MODE: {
|
|
84
|
+
readonly NORMAL: ImageMode;
|
|
85
|
+
readonly DOUBLE_WIDTH: ImageMode;
|
|
86
|
+
readonly DOUBLE_HEIGHT: ImageMode;
|
|
87
|
+
readonly QUADRUPLE: ImageMode;
|
|
88
|
+
};
|
|
89
|
+
export declare const CUT_MODE: {
|
|
90
|
+
readonly FULL: CutMode;
|
|
91
|
+
readonly PARTIAL: CutMode;
|
|
92
|
+
};
|
|
93
|
+
export declare const CODE_PAGE: {
|
|
94
|
+
/** Strips accents and special chars to plain ASCII. Use when the printer
|
|
95
|
+
* ignores ESC t commands. á→a, é→e, ñ→n, ß→ss, ¿→?, €→EUR, etc. */
|
|
96
|
+
readonly ACCENT_REMOVER: CodePage;
|
|
97
|
+
};
|
|
2
98
|
export interface PrinterOptions {
|
|
3
99
|
cut_paper: boolean;
|
|
4
100
|
beep: boolean;
|
|
5
101
|
open_cash_drawer: boolean;
|
|
102
|
+
/** Character encoding for the printer. Default: `{ Page: 0 }` (CP437, ASCII only). */
|
|
103
|
+
code_page?: CodePage;
|
|
6
104
|
}
|
|
7
105
|
export interface GlobalStyles {
|
|
8
106
|
bold?: boolean;
|
|
9
107
|
underline?: boolean;
|
|
10
|
-
align?:
|
|
108
|
+
align?: TextAlign;
|
|
11
109
|
italic?: boolean;
|
|
12
110
|
invert?: boolean;
|
|
13
|
-
font?:
|
|
111
|
+
font?: TextFont;
|
|
14
112
|
rotate?: boolean;
|
|
15
113
|
upside_down?: boolean;
|
|
16
|
-
size?:
|
|
114
|
+
size?: TextSize;
|
|
17
115
|
}
|
|
18
116
|
export interface Title {
|
|
19
117
|
text: string;
|
|
@@ -28,19 +126,21 @@ export interface Text {
|
|
|
28
126
|
styles?: GlobalStyles;
|
|
29
127
|
}
|
|
30
128
|
export interface Feed {
|
|
31
|
-
feed_type:
|
|
129
|
+
feed_type: FeedType;
|
|
32
130
|
value: number;
|
|
33
131
|
}
|
|
34
132
|
export interface Cut {
|
|
35
|
-
mode:
|
|
133
|
+
mode: CutMode;
|
|
36
134
|
feed: number;
|
|
37
135
|
}
|
|
38
136
|
export interface Beep {
|
|
137
|
+
/** Number of beeps (1–9) */
|
|
39
138
|
times: number;
|
|
139
|
+
/** Duration per beep in ms (1–255) */
|
|
40
140
|
duration: number;
|
|
41
141
|
}
|
|
42
142
|
export interface Drawer {
|
|
43
|
-
pin:
|
|
143
|
+
pin: 2 | 5;
|
|
44
144
|
pulse_time: number;
|
|
45
145
|
}
|
|
46
146
|
export interface Table {
|
|
@@ -52,43 +152,56 @@ export interface Table {
|
|
|
52
152
|
}
|
|
53
153
|
export interface Qr {
|
|
54
154
|
data: string;
|
|
155
|
+
/** Module size 1–16 (default 6) */
|
|
55
156
|
size: number;
|
|
56
|
-
error_correction:
|
|
57
|
-
model:
|
|
58
|
-
align?:
|
|
157
|
+
error_correction: QrErrorCorrection;
|
|
158
|
+
model: 1 | 2;
|
|
159
|
+
align?: TextAlign;
|
|
59
160
|
}
|
|
60
161
|
export interface Barcode {
|
|
61
162
|
data: string;
|
|
62
|
-
barcode_type:
|
|
163
|
+
barcode_type: BarcodeType;
|
|
164
|
+
/** Bar width 2–6 */
|
|
63
165
|
width: number;
|
|
166
|
+
/** Bar height in dots (1–255) */
|
|
64
167
|
height: number;
|
|
65
|
-
text_position:
|
|
66
|
-
align?:
|
|
168
|
+
text_position: BarcodeTextPosition;
|
|
169
|
+
align?: TextAlign;
|
|
67
170
|
}
|
|
68
171
|
export interface DataMatrixModel {
|
|
69
172
|
data: string;
|
|
173
|
+
/** Module size 1–16 */
|
|
70
174
|
size: number;
|
|
71
175
|
}
|
|
72
176
|
export interface Pdf417 {
|
|
73
177
|
data: string;
|
|
178
|
+
/** Columns 0 (auto) or 1–30 */
|
|
74
179
|
columns: number;
|
|
180
|
+
/** Rows 0 (auto) or 3–90 */
|
|
75
181
|
rows: number;
|
|
182
|
+
/** Module width 2–8 */
|
|
76
183
|
width: number;
|
|
184
|
+
/** Row height 2–8 */
|
|
77
185
|
height: number;
|
|
186
|
+
/** Error correction level 0–8 */
|
|
78
187
|
error_correction: number;
|
|
79
188
|
}
|
|
80
189
|
export interface Image {
|
|
190
|
+
/** Base64 encoded image (with or without data URI prefix) */
|
|
81
191
|
data: string;
|
|
192
|
+
/** Max width in pixels. 0 = use full paper width. */
|
|
82
193
|
max_width: number;
|
|
83
|
-
align:
|
|
194
|
+
align: TextAlign;
|
|
84
195
|
dithering: boolean;
|
|
85
|
-
size:
|
|
196
|
+
size: ImageMode;
|
|
86
197
|
}
|
|
87
198
|
export interface Logo {
|
|
199
|
+
/** NV memory key code (1–255) */
|
|
88
200
|
key_code: number;
|
|
89
|
-
mode:
|
|
201
|
+
mode: ImageMode;
|
|
90
202
|
}
|
|
91
203
|
export interface Line {
|
|
204
|
+
/** Single character to repeat across the paper width (default '-') */
|
|
92
205
|
character: string;
|
|
93
206
|
}
|
|
94
207
|
export type PrintSections = {
|
|
@@ -139,6 +252,8 @@ export interface PrinterInfo {
|
|
|
139
252
|
export interface TestPrintRequest {
|
|
140
253
|
printer_info: PrintJobRequest;
|
|
141
254
|
include_text?: boolean;
|
|
255
|
+
include_custom_text?: boolean;
|
|
256
|
+
custom_text?: string | null;
|
|
142
257
|
include_text_styles?: boolean;
|
|
143
258
|
include_alignment?: boolean;
|
|
144
259
|
include_columns?: boolean;
|
|
@@ -156,6 +271,75 @@ export interface TestPrintRequest {
|
|
|
156
271
|
test_invert?: boolean;
|
|
157
272
|
test_rotate?: boolean;
|
|
158
273
|
}
|
|
159
|
-
|
|
274
|
+
/** Creates a Title section */
|
|
275
|
+
export declare function title(text: string, styles?: GlobalStyles): PrintSections;
|
|
276
|
+
/** Creates a Subtitle section */
|
|
277
|
+
export declare function subtitle(text: string, styles?: GlobalStyles): PrintSections;
|
|
278
|
+
/** Creates a Text section */
|
|
279
|
+
export declare function text(text: string, styles?: GlobalStyles): PrintSections;
|
|
280
|
+
/** Creates a Line separator section */
|
|
281
|
+
export declare function line(character?: string): PrintSections;
|
|
282
|
+
/** Creates a Feed section */
|
|
283
|
+
export declare function feed(value: number, feed_type?: FeedType): PrintSections;
|
|
284
|
+
/** Creates a Cut section */
|
|
285
|
+
export declare function cut(mode?: CutMode, feedLines?: number): PrintSections;
|
|
286
|
+
/** Creates a GlobalStyles section — affects all subsequent sections until changed */
|
|
287
|
+
export declare function globalStyles(styles: GlobalStyles): PrintSections;
|
|
288
|
+
/** Creates a Beep section */
|
|
289
|
+
export declare function beep(times?: number, duration?: number): PrintSections;
|
|
290
|
+
/** Creates a Drawer section */
|
|
291
|
+
export declare function drawer(pin?: 2 | 5, pulse_time?: number): PrintSections;
|
|
292
|
+
/** Creates a Table section */
|
|
293
|
+
export declare function table(columns: number, body: Text[][], options?: {
|
|
294
|
+
column_widths?: number[];
|
|
295
|
+
header?: Text[];
|
|
296
|
+
truncate?: boolean;
|
|
297
|
+
}): PrintSections;
|
|
298
|
+
/** Creates a QR section */
|
|
299
|
+
export declare function qr(data: string, options?: {
|
|
300
|
+
size?: number;
|
|
301
|
+
error_correction?: QrErrorCorrection;
|
|
302
|
+
model?: 1 | 2;
|
|
303
|
+
align?: TextAlign;
|
|
304
|
+
}): PrintSections;
|
|
305
|
+
/** Creates a Barcode section */
|
|
306
|
+
export declare function barcode(data: string, barcode_type?: BarcodeType, options?: {
|
|
307
|
+
width?: number;
|
|
308
|
+
height?: number;
|
|
309
|
+
text_position?: BarcodeTextPosition;
|
|
310
|
+
align?: TextAlign;
|
|
311
|
+
}): PrintSections;
|
|
312
|
+
/** Creates a DataMatrix section */
|
|
313
|
+
export declare function dataMatrix(data: string, size?: number): PrintSections;
|
|
314
|
+
/** Creates a PDF417 section */
|
|
315
|
+
export declare function pdf417(data: string, options?: {
|
|
316
|
+
columns?: number;
|
|
317
|
+
rows?: number;
|
|
318
|
+
width?: number;
|
|
319
|
+
height?: number;
|
|
320
|
+
error_correction?: number;
|
|
321
|
+
}): PrintSections;
|
|
322
|
+
/** Creates an Image section */
|
|
323
|
+
export declare function image(data: string, options?: {
|
|
324
|
+
max_width?: number;
|
|
325
|
+
align?: TextAlign;
|
|
326
|
+
dithering?: boolean;
|
|
327
|
+
size?: ImageMode;
|
|
328
|
+
}): PrintSections;
|
|
329
|
+
/** Creates a Logo section */
|
|
330
|
+
export declare function logo(key_code: number, mode?: ImageMode): PrintSections;
|
|
331
|
+
/**
|
|
332
|
+
* Sends a print job to the specified thermal printer.
|
|
333
|
+
* @throws {string} Error message from the printer or document generation if the job fails.
|
|
334
|
+
*/
|
|
335
|
+
export declare function print_thermal_printer(printJobRequest: PrintJobRequest): Promise<void>;
|
|
336
|
+
/**
|
|
337
|
+
* Returns the list of available thermal printers on the current system.
|
|
338
|
+
* @throws {string} Error message if printer enumeration fails.
|
|
339
|
+
*/
|
|
160
340
|
export declare function list_thermal_printers(): Promise<PrinterInfo[]>;
|
|
161
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Sends a test print job to verify the printer is working correctly.
|
|
343
|
+
* @throws {string} Error message from the printer or document generation if the job fails.
|
|
344
|
+
*/
|
|
345
|
+
export declare function test_thermal_printer(testPrintRequest: TestPrintRequest): Promise<void>;
|