@hoangnh0099/react-native-sunmi-printer 0.2.0 → 0.4.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 +121 -42
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/sunmiprinter/SunmiPrinterModule.kt +521 -161
- package/lib/module/NativeSunmiPrinter.js.map +1 -1
- package/lib/module/index.js +50 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeSunmiPrinter.d.ts +16 -0
- package/lib/typescript/src/NativeSunmiPrinter.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +16 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +4 -7
- package/src/NativeSunmiPrinter.ts +25 -0
- package/src/index.tsx +73 -0
- package/SunmiPrinter.podspec +0 -20
- package/ios/SunmiPrinter.h +0 -5
- package/ios/SunmiPrinter.mm +0 -21
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @hoangnh0099/react-native-sunmi-printer
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@hoangnh0099/react-native-sunmi-printer)
|
|
4
4
|
[](https://github.com/ngxhuyhoang/react-native-sunmi-printer/blob/main/LICENSE)
|
|
5
5
|
[](#supported-devices)
|
|
6
6
|
[](#)
|
|
7
7
|
|
|
8
8
|
React Native library for Sunmi built-in printers. Supports Sunmi V2S and newer devices (Android 11+).
|
|
9
9
|
|
|
10
|
-
Built with **React Native New Architecture** (TurboModule)
|
|
10
|
+
Built with **React Native New Architecture** (TurboModule) and **Sunmi PrinterX SDK**.
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
@@ -43,18 +43,50 @@ await printImage(base64String);
|
|
|
43
43
|
await lineWrap(3);
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
### Print with Styles (Bold, Italic, Underline)
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import {
|
|
50
|
+
setPrinterStyle,
|
|
51
|
+
printText,
|
|
52
|
+
lineWrap,
|
|
53
|
+
printerInit,
|
|
54
|
+
} from '@hoangnh0099/react-native-sunmi-printer';
|
|
55
|
+
|
|
56
|
+
// setPrinterStyle(key, value)
|
|
57
|
+
// Keys: 0=Bold, 1=Underline, 2=AntiWhite, 3=Strikethrough,
|
|
58
|
+
// 4=Italic, 5=Invert, 14=DoubleWidth, 15=DoubleHeight
|
|
59
|
+
// Value: 1=Enable, 0=Disable
|
|
60
|
+
await setPrinterStyle(0, 1); // Bold ON
|
|
61
|
+
await setPrinterStyle(1, 1); // Underline ON
|
|
62
|
+
await printText('Bold & Underlined\n');
|
|
63
|
+
await printerInit(); // Reset all styles
|
|
64
|
+
await lineWrap(3);
|
|
65
|
+
```
|
|
66
|
+
|
|
46
67
|
### Print QR Code
|
|
47
68
|
|
|
48
69
|
```js
|
|
49
70
|
import { printQRCode, lineWrap } from '@hoangnh0099/react-native-sunmi-printer';
|
|
50
71
|
|
|
51
72
|
// printQRCode(data, moduleSize, errorLevel)
|
|
52
|
-
// moduleSize:
|
|
73
|
+
// moduleSize: 4-16
|
|
53
74
|
// errorLevel: 0=L(7%), 1=M(15%), 2=Q(25%), 3=H(30%)
|
|
54
75
|
await printQRCode('https://example.com', 8, 2);
|
|
55
76
|
await lineWrap(3);
|
|
56
77
|
```
|
|
57
78
|
|
|
79
|
+
### Print 2D Barcode (PDF417 / DataMatrix)
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
import { print2DCode, lineWrap } from '@hoangnh0099/react-native-sunmi-printer';
|
|
83
|
+
|
|
84
|
+
// print2DCode(data, symbology, moduleSize, errorLevel)
|
|
85
|
+
// symbology: 1=QR, 2=PDF417, 3=DataMatrix
|
|
86
|
+
await print2DCode('Hello PDF417', 2, 2, 2);
|
|
87
|
+
await lineWrap(3);
|
|
88
|
+
```
|
|
89
|
+
|
|
58
90
|
### Print Barcode
|
|
59
91
|
|
|
60
92
|
```js
|
|
@@ -146,8 +178,8 @@ const state = await updatePrinterState();
|
|
|
146
178
|
| `getPrinterSerialNo()` | `Promise<string>` | Printer serial number |
|
|
147
179
|
| `getPrinterVersion()` | `Promise<string>` | Firmware version |
|
|
148
180
|
| `getPrinterModal()` | `Promise<string>` | Device model |
|
|
149
|
-
| `getPrinterPaper()` | `Promise<number>` | Paper
|
|
150
|
-
| `getPrinterMode()` | `Promise<number>` | Mode (0=
|
|
181
|
+
| `getPrinterPaper()` | `Promise<number>` | Paper width in mm (58 or 80) |
|
|
182
|
+
| `getPrinterMode()` | `Promise<number>` | Mode (0=thermal, 1=black mark, 2=label) |
|
|
151
183
|
| `getServiceVersion()` | `Promise<string>` | Print service version |
|
|
152
184
|
| `getFirmwareStatus()` | `Promise<number>` | Firmware status |
|
|
153
185
|
| `updatePrinterState()` | `Promise<number>` | Current printer state |
|
|
@@ -172,9 +204,39 @@ const state = await updatePrinterState();
|
|
|
172
204
|
| Method | Description |
|
|
173
205
|
| ----------------------------- | ----------------------------------------- |
|
|
174
206
|
| `setAlignment(alignment)` | Set alignment (0=left, 1=center, 2=right) |
|
|
175
|
-
| `setFontName(typeface)` | Set
|
|
207
|
+
| `setFontName(typeface)` | Set custom vector font name |
|
|
176
208
|
| `setFontSize(fontsize)` | Set font size |
|
|
177
|
-
| `setPrinterStyle(key, value)` | Set
|
|
209
|
+
| `setPrinterStyle(key, value)` | Set print style (see table below) |
|
|
210
|
+
|
|
211
|
+
**`setPrinterStyle` Keys:**
|
|
212
|
+
|
|
213
|
+
| Key | Constant | Values |
|
|
214
|
+
| --- | -------------------- | ----------------- |
|
|
215
|
+
| 0 | `ENABLE_BOLD` | 0=off, 1=on |
|
|
216
|
+
| 1 | `ENABLE_UNDERLINE` | 0=off, 1=on |
|
|
217
|
+
| 2 | `ENABLE_ANTI_WHITE` | 0=off, 1=on |
|
|
218
|
+
| 3 | `ENABLE_STRIKETHROUGH` | 0=off, 1=on |
|
|
219
|
+
| 4 | `ENABLE_ITALIC` | 0=off, 1=on |
|
|
220
|
+
| 5 | `ENABLE_INVERT` | 0=off, 1=on |
|
|
221
|
+
| 6 | `SET_TEXT_RIGHT_SPACING` | pixels |
|
|
222
|
+
| 9 | `SET_LINE_SPACING` | pixels |
|
|
223
|
+
| 14 | `ENABLE_DOUBLE_WIDTH` | 0=off, 1=on |
|
|
224
|
+
| 15 | `ENABLE_DOUBLE_HEIGHT` | 0=off, 1=on |
|
|
225
|
+
|
|
226
|
+
</details>
|
|
227
|
+
|
|
228
|
+
<details>
|
|
229
|
+
<summary><b>Print Style Query</b></summary>
|
|
230
|
+
|
|
231
|
+
| Method | Return | Description |
|
|
232
|
+
| --------------------- | ------------------- | ------------------------------------------------- |
|
|
233
|
+
| `getForcedDouble()` | `Promise<number>` | 0=none, 1=width, 2=height, 3=both |
|
|
234
|
+
| `isForcedBold()` | `Promise<boolean>` | Whether bold is currently enabled |
|
|
235
|
+
| `isForcedUnderline()` | `Promise<boolean>` | Whether underline is currently enabled |
|
|
236
|
+
| `isForcedAntiWhite()` | `Promise<boolean>` | Whether anti-white is currently enabled |
|
|
237
|
+
| `getForcedRowHeight()` | `Promise<number>` | Current line spacing (-1=default) |
|
|
238
|
+
| `getCurrentFontName()` | `Promise<string>` | Current font name (empty=default) |
|
|
239
|
+
| `getPrinterDensity()` | `Promise<number>` | Print density level |
|
|
178
240
|
|
|
179
241
|
</details>
|
|
180
242
|
|
|
@@ -195,7 +257,7 @@ const state = await updatePrinterState();
|
|
|
195
257
|
| Method | Description |
|
|
196
258
|
| --------------------------------- | ------------------------------------------------------- |
|
|
197
259
|
| `printImage(base64)` | Print base64-encoded image |
|
|
198
|
-
| `printBitmapCustom(base64, type)` | Print with mode (0=
|
|
260
|
+
| `printBitmapCustom(base64, type)` | Print with mode (0=binarization, 1=dithering) |
|
|
199
261
|
|
|
200
262
|
> Max width: 384px (58mm) or 576px (80mm). Call `lineWrap()` after printing to feed paper.
|
|
201
263
|
|
|
@@ -204,10 +266,11 @@ const state = await updatePrinterState();
|
|
|
204
266
|
<details>
|
|
205
267
|
<summary><b>Barcode</b></summary>
|
|
206
268
|
|
|
207
|
-
| Method | Description
|
|
208
|
-
| ------------------------------------------------------------ |
|
|
209
|
-
| `printBarCode(data, symbology, height, width, textPosition)` | Print barcode
|
|
210
|
-
| `printQRCode(data, moduleSize, errorLevel)` | Print QR code
|
|
269
|
+
| Method | Description |
|
|
270
|
+
| ------------------------------------------------------------ | ----------------------------------------------- |
|
|
271
|
+
| `printBarCode(data, symbology, height, width, textPosition)` | Print 1D barcode |
|
|
272
|
+
| `printQRCode(data, moduleSize, errorLevel)` | Print QR code |
|
|
273
|
+
| `print2DCode(data, symbology, moduleSize, errorLevel)` | Print 2D barcode (1=QR, 2=PDF417, 3=DataMatrix) |
|
|
211
274
|
|
|
212
275
|
</details>
|
|
213
276
|
|
|
@@ -216,62 +279,74 @@ const state = await updatePrinterState();
|
|
|
216
279
|
|
|
217
280
|
| Method | Description |
|
|
218
281
|
| ------------------------------------------- | ---------------------------------------------- |
|
|
219
|
-
| `printColumnsText(texts, widths, aligns)` | Print columns (widths
|
|
220
|
-
| `printColumnsString(texts, widths, aligns)` |
|
|
282
|
+
| `printColumnsText(texts, widths, aligns)` | Print columns (widths as proportional weights) |
|
|
283
|
+
| `printColumnsString(texts, widths, aligns)` | Alias for `printColumnsText` |
|
|
221
284
|
|
|
222
285
|
</details>
|
|
223
286
|
|
|
224
287
|
<details>
|
|
225
288
|
<summary><b>Raw / Paper</b></summary>
|
|
226
289
|
|
|
227
|
-
| Method
|
|
228
|
-
|
|
|
229
|
-
| `sendRAWData(data)` | Send raw ESC/POS byte array
|
|
230
|
-
| `lineWrap(lines)` | Feed paper by N lines
|
|
231
|
-
| `cutPaper()`
|
|
232
|
-
| `autoOutPaper()`
|
|
290
|
+
| Method | Return | Description |
|
|
291
|
+
| ----------------------- | ----------------- | --------------------------------- |
|
|
292
|
+
| `sendRAWData(data)` | `Promise<void>` | Send raw ESC/POS byte array |
|
|
293
|
+
| `lineWrap(lines)` | `Promise<void>` | Feed paper by N lines |
|
|
294
|
+
| `cutPaper()` | `Promise<void>` | Cut paper (if cutter available) |
|
|
295
|
+
| `autoOutPaper()` | `Promise<void>` | Auto feed paper to tear position |
|
|
296
|
+
| `getCutPaperTimes()` | `Promise<number>` | Get total cutter usage count |
|
|
297
|
+
| `getPrinterBBMDistance()` | `Promise<number>` | Get black mark paper feed distance |
|
|
233
298
|
|
|
234
299
|
</details>
|
|
235
300
|
|
|
236
301
|
<details>
|
|
237
302
|
<summary><b>Cash Drawer</b></summary>
|
|
238
303
|
|
|
239
|
-
| Method
|
|
240
|
-
|
|
|
241
|
-
| `openDrawer()` | Open cash drawer (if available)
|
|
304
|
+
| Method | Return | Description |
|
|
305
|
+
| -------------------- | ----------------- | ----------------------------------- |
|
|
306
|
+
| `openDrawer()` | `Promise<void>` | Open cash drawer (if available) |
|
|
307
|
+
| `getDrawerStatus()` | `Promise<number>` | Drawer state (0=closed, 1=open) |
|
|
308
|
+
| `getOpenDrawerTimes()` | `Promise<number>` | Total drawer open count |
|
|
242
309
|
|
|
243
310
|
</details>
|
|
244
311
|
|
|
245
312
|
<details>
|
|
246
313
|
<summary><b>Label</b></summary>
|
|
247
314
|
|
|
248
|
-
| Method | Description
|
|
249
|
-
| --------------- |
|
|
250
|
-
| `labelLocate()` |
|
|
251
|
-
| `labelOutput()` |
|
|
315
|
+
| Method | Description |
|
|
316
|
+
| --------------- | ------------------------------------------------ |
|
|
317
|
+
| `labelLocate()` | Position the next label (set device to Label Mode first) |
|
|
318
|
+
| `labelOutput()` | Output the label to the cutting position |
|
|
319
|
+
|
|
320
|
+
> **Note:** Enable Label Mode in device settings: Print Settings > Built-in Setting > Printer Mode > Label Mode.
|
|
252
321
|
|
|
253
322
|
</details>
|
|
254
323
|
|
|
255
324
|
<details>
|
|
256
325
|
<summary><b>LCD Customer Display</b></summary>
|
|
257
326
|
|
|
258
|
-
| Method
|
|
259
|
-
|
|
|
260
|
-
| `sendLCDCommand(flag)`
|
|
261
|
-
| `
|
|
262
|
-
| `
|
|
263
|
-
| `
|
|
327
|
+
| Method | Description |
|
|
328
|
+
| ----------------------------------------- | --------------------------------------------------- |
|
|
329
|
+
| `sendLCDCommand(flag)` | LCD command (1=init, 2=wake, 3=sleep, 4=clear) |
|
|
330
|
+
| `sendLCDString(text)` | Display single-line text on LCD |
|
|
331
|
+
| `sendLCDDoubleString(topText, bottomText)` | Display two lines on LCD |
|
|
332
|
+
| `sendLCDFillString(text, size, fill)` | Display text with custom size (fill=stretch to fit) |
|
|
333
|
+
| `sendLCDMultiString(texts, align)` | Display multi-line text (auto-sized by weight) |
|
|
334
|
+
| `sendLCDBitmap(base64)` | Display image on LCD (max 128x40px) |
|
|
335
|
+
|
|
336
|
+
> Only available on mini-series desktop devices with a customer display (T1mini, T2mini, etc.).
|
|
264
337
|
|
|
265
338
|
</details>
|
|
266
339
|
|
|
267
340
|
<details>
|
|
268
341
|
<summary><b>Transaction</b></summary>
|
|
269
342
|
|
|
270
|
-
| Method
|
|
271
|
-
|
|
|
272
|
-
| `enterPrinterBuffer(clean)`
|
|
273
|
-
| `exitPrinterBuffer(commit)`
|
|
274
|
-
| `commitPrinterBuffer()`
|
|
343
|
+
| Method | Description |
|
|
344
|
+
| --------------------------------------- | -------------------------------------------- |
|
|
345
|
+
| `enterPrinterBuffer(clean)` | Start buffering commands |
|
|
346
|
+
| `exitPrinterBuffer(commit)` | Exit buffer (commit=true to print) |
|
|
347
|
+
| `commitPrinterBuffer()` | Print buffer contents (stays in buffer mode) |
|
|
348
|
+
| `exitPrinterBufferWithCallback(commit)` | Exit buffer with print result callback |
|
|
349
|
+
| `commitPrinterBufferWithCallback()` | Commit buffer with print result callback |
|
|
275
350
|
|
|
276
351
|
</details>
|
|
277
352
|
|
|
@@ -287,6 +362,14 @@ const state = await updatePrinterState();
|
|
|
287
362
|
|
|
288
363
|
---
|
|
289
364
|
|
|
365
|
+
## Sponsors
|
|
366
|
+
|
|
367
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
|
|
368
|
+
|
|
369
|
+
[](https://github.com/sponsors/ngxhuyhoang)
|
|
370
|
+
|
|
371
|
+
<a href="https://buymeacoffee.com/hoangnh0099" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me a Beer" height="40"></a>
|
|
372
|
+
|
|
290
373
|
## Contributing
|
|
291
374
|
|
|
292
375
|
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
@@ -294,7 +377,3 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
|
|
|
294
377
|
## License
|
|
295
378
|
|
|
296
379
|
[MIT](LICENSE)
|
|
297
|
-
|
|
298
|
-
---
|
|
299
|
-
|
|
300
|
-
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
package/android/build.gradle
CHANGED