@rejaul/react-native-printer-kit 0.1.1 → 0.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/README.md +67 -12
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/rejaul/reactnativeprinterkit/ReactNativePrinterKitModule.kt +131 -31
- package/lib/module/NativeReactNativePrinterKit.js.map +1 -1
- package/lib/module/index.js +17 -17
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeReactNativePrinterKit.d.ts +74 -16
- package/lib/typescript/src/NativeReactNativePrinterKit.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +11 -11
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeReactNativePrinterKit.ts +82 -45
- package/src/index.tsx +37 -53
package/README.md
CHANGED
|
@@ -76,13 +76,13 @@ async function printReceipt() {
|
|
|
76
76
|
// 2. List paired printers and connect to one
|
|
77
77
|
const printers = getBondedBluetoothPrinters();
|
|
78
78
|
if (printers.length === 0) return;
|
|
79
|
-
await connectPrinter(printers[0]!.address);
|
|
79
|
+
await connectPrinter({ address: printers[0]!.address });
|
|
80
80
|
|
|
81
81
|
// 3a. Print plain text
|
|
82
|
-
await printText('Hello from PrinterKit');
|
|
82
|
+
await printText({ text: 'Hello from PrinterKit' });
|
|
83
83
|
|
|
84
84
|
// 3b. Or print a full HTML receipt (Bangla, styling, everything)
|
|
85
|
-
const ok = await printHtml(myReceiptHtml);
|
|
85
|
+
const ok = await printHtml({ html: myReceiptHtml });
|
|
86
86
|
console.log('Printed:', ok);
|
|
87
87
|
}
|
|
88
88
|
```
|
|
@@ -113,12 +113,14 @@ Whether `BLUETOOTH_CONNECT` specifically is already granted (always `true` below
|
|
|
113
113
|
#### `requestBluetoothPermission(): Promise<boolean>`
|
|
114
114
|
Shows the system permission dialog(s) for whatever's needed on this Android version — `BLUETOOTH_CONNECT` (12+) and `POST_NOTIFICATIONS` (13+, for the persistent-connection notification's visibility) — and resolves based on `BLUETOOTH_CONNECT`'s result specifically. A denied `POST_NOTIFICATIONS` alone doesn't make this resolve `false`: printing still works, the notification just won't show.
|
|
115
115
|
|
|
116
|
+
Every function that takes data (anything beyond a bare callback) takes a single params object instead of positional arguments, so new fields can be added later without breaking existing call sites.
|
|
117
|
+
|
|
116
118
|
### Connection
|
|
117
119
|
|
|
118
120
|
#### `getBondedBluetoothPrinters(): BluetoothPrinterDevice[]`
|
|
119
121
|
Lists Bluetooth devices already paired with the phone via Android's own Bluetooth settings.
|
|
120
122
|
|
|
121
|
-
#### `connectPrinter(
|
|
123
|
+
#### `connectPrinter(params: ConnectPrinterParams): Promise<boolean>`
|
|
122
124
|
Opens an RFCOMM/SPP connection to the paired printer. Closes any existing connection first, and remembers the address for auto-reconnect on the next app launch.
|
|
123
125
|
|
|
124
126
|
#### `disconnectPrinter(): Promise<void>`
|
|
@@ -132,26 +134,26 @@ The currently connected printer, if any.
|
|
|
132
134
|
|
|
133
135
|
### Printing
|
|
134
136
|
|
|
135
|
-
#### `printText(
|
|
137
|
+
#### `printText(params: PrintTextParams): Promise<void>`
|
|
136
138
|
Prints raw text using the printer's built-in font. **ASCII only** — use `printHtml()` for Bangla or other non-Latin scripts.
|
|
137
139
|
|
|
138
|
-
#### `printImage(
|
|
140
|
+
#### `printImage(params: PrintImageParams): Promise<void>`
|
|
139
141
|
Prints an image file as a dithered ESC/POS raster image. `printerWidthDots`: 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
140
142
|
|
|
141
|
-
#### `printImageBase64(
|
|
143
|
+
#### `printImageBase64(params: PrintImageBase64Params): Promise<void>`
|
|
142
144
|
Same as above, from a base64-encoded image string.
|
|
143
145
|
|
|
144
|
-
#### `pdfToImage(
|
|
146
|
+
#### `pdfToImage(params: PdfToImageParams): Promise<string>`
|
|
145
147
|
Renders one PDF page to an image file and returns its path.
|
|
146
148
|
|
|
147
|
-
#### `printPdf(
|
|
149
|
+
#### `printPdf(params: PrintPdfParams): Promise<void>`
|
|
148
150
|
`pdfToImage` + print, in one call.
|
|
149
151
|
|
|
150
|
-
#### `htmlToPdf(
|
|
152
|
+
#### `htmlToPdf(params: HtmlToPdfParams): Promise<string | null>`
|
|
151
153
|
Renders HTML to a PDF file using an off-screen `WebView` and returns its path, or `null` on failure. `pageWidthDp` controls how large the content renders (like a CSS viewport width), independent of the final printed width. Leave `heightDp` unset to auto-measure the real content height (recommended).
|
|
152
154
|
|
|
153
|
-
#### `printHtml(
|
|
154
|
-
Full pipeline: `htmlToPdf` → `printPdf`. This is how you print Bangla (or other non-Latin) text or any real HTML/CSS layout.
|
|
155
|
+
#### `printHtml(params: PrintHtmlParams): Promise<boolean>`
|
|
156
|
+
Full pipeline: `htmlToPdf` → `printPdf`. This is how you print Bangla (or other non-Latin) text or any real HTML/CSS layout. Retries once (reconnect + resend) if the underlying write fails, e.g. from a "Broken pipe" when a cheap board drops the link mid-print.
|
|
155
157
|
|
|
156
158
|
## Type Definitions
|
|
157
159
|
|
|
@@ -162,6 +164,59 @@ type BluetoothPrinterDevice = {
|
|
|
162
164
|
};
|
|
163
165
|
|
|
164
166
|
type PrinterImageType = 'PNG' | 'JPEG';
|
|
167
|
+
|
|
168
|
+
type ConnectPrinterParams = { address: string };
|
|
169
|
+
|
|
170
|
+
type PrintTextParams = { text: string; feedLines?: number };
|
|
171
|
+
|
|
172
|
+
type PrintImageParams = {
|
|
173
|
+
imagePath: string;
|
|
174
|
+
printerWidthDots?: number;
|
|
175
|
+
feedLines?: number;
|
|
176
|
+
bandHeightDots?: number; // default 16 - lower for printers that drop/garble large images
|
|
177
|
+
bandDelayMs?: number; // default 60 - raise for printers that drop/garble large images
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
type PrintImageBase64Params = {
|
|
181
|
+
base64: string;
|
|
182
|
+
printerWidthDots?: number;
|
|
183
|
+
feedLines?: number;
|
|
184
|
+
bandHeightDots?: number;
|
|
185
|
+
bandDelayMs?: number;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
type PdfToImageParams = {
|
|
189
|
+
pdfPath: string;
|
|
190
|
+
imageType?: PrinterImageType;
|
|
191
|
+
page?: number;
|
|
192
|
+
targetWidthPx?: number;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
type PrintPdfParams = {
|
|
196
|
+
pdfPath: string;
|
|
197
|
+
printerWidthDots?: number;
|
|
198
|
+
page?: number;
|
|
199
|
+
feedLines?: number;
|
|
200
|
+
bandHeightDots?: number;
|
|
201
|
+
bandDelayMs?: number;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
type HtmlToPdfParams = {
|
|
205
|
+
html: string;
|
|
206
|
+
pageWidthDp?: number;
|
|
207
|
+
heightDp?: number;
|
|
208
|
+
minPageHeightDp?: number;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
type PrintHtmlParams = {
|
|
212
|
+
html: string;
|
|
213
|
+
printerWidthDots?: number;
|
|
214
|
+
pageWidthDp?: number;
|
|
215
|
+
heightDp?: number;
|
|
216
|
+
minPageHeightDp?: number;
|
|
217
|
+
bandHeightDots?: number;
|
|
218
|
+
bandDelayMs?: number;
|
|
219
|
+
};
|
|
165
220
|
```
|
|
166
221
|
|
|
167
222
|
## Persistent connection & auto-reconnect
|
package/android/build.gradle
CHANGED
package/android/src/main/java/com/rejaul/reactnativeprinterkit/ReactNativePrinterKitModule.kt
CHANGED
|
@@ -10,6 +10,7 @@ import androidx.core.content.ContextCompat
|
|
|
10
10
|
import com.facebook.react.bridge.Arguments
|
|
11
11
|
import com.facebook.react.bridge.Promise
|
|
12
12
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
13
|
+
import com.facebook.react.bridge.ReadableMap
|
|
13
14
|
import com.facebook.react.bridge.WritableArray
|
|
14
15
|
import com.facebook.react.bridge.WritableMap
|
|
15
16
|
import com.facebook.react.modules.core.PermissionAwareActivity
|
|
@@ -17,9 +18,29 @@ import com.rezaul.printerkit.BluetoothPermissions
|
|
|
17
18
|
import com.rezaul.printerkit.BluetoothPrinter
|
|
18
19
|
import com.rezaul.printerkit.BluetoothPrinterDevice
|
|
19
20
|
import com.rezaul.printerkit.BluetoothPrinterService
|
|
21
|
+
import com.rezaul.printerkit.ConnectPrinterParams
|
|
22
|
+
import com.rezaul.printerkit.HtmlToPdfParams
|
|
23
|
+
import com.rezaul.printerkit.PdfToImageParams
|
|
24
|
+
import com.rezaul.printerkit.PrintHtmlParams
|
|
25
|
+
import com.rezaul.printerkit.PrintImageBase64Params
|
|
26
|
+
import com.rezaul.printerkit.PrintImageFileParams
|
|
27
|
+
import com.rezaul.printerkit.PrintPdfParams
|
|
20
28
|
import com.rezaul.printerkit.PrinterImageType
|
|
29
|
+
import com.rezaul.printerkit.PrintTextParams
|
|
21
30
|
import java.util.concurrent.Executors
|
|
22
31
|
|
|
32
|
+
/** Reads an optional numeric field, falling back to [default] if absent/null. */
|
|
33
|
+
private fun ReadableMap.optInt(key: String, default: Int): Int =
|
|
34
|
+
if (hasKey(key) && !isNull(key)) getDouble(key).toInt() else default
|
|
35
|
+
|
|
36
|
+
/** Reads an optional numeric field, or null if absent/null. */
|
|
37
|
+
private fun ReadableMap.optIntOrNull(key: String): Int? =
|
|
38
|
+
if (hasKey(key) && !isNull(key)) getDouble(key).toInt() else null
|
|
39
|
+
|
|
40
|
+
/** Reads an optional numeric field as a Long, falling back to [default] if absent/null. */
|
|
41
|
+
private fun ReadableMap.optLong(key: String, default: Long): Long =
|
|
42
|
+
if (hasKey(key) && !isNull(key)) getDouble(key).toLong() else default
|
|
43
|
+
|
|
23
44
|
/**
|
|
24
45
|
* Bridges [com.rezaul.printerkit.BluetoothPrinter] to React Native.
|
|
25
46
|
*
|
|
@@ -32,6 +53,10 @@ import java.util.concurrent.Executors
|
|
|
32
53
|
* All blocking Bluetooth/PDF/image I/O runs on a single background executor, off the
|
|
33
54
|
* calling (JS) thread - also serializing printer writes, since concurrent writes to
|
|
34
55
|
* the same socket from two overlapping calls would corrupt the output.
|
|
56
|
+
*
|
|
57
|
+
* Every JS-facing method that takes data receives a single [ReadableMap] (the object
|
|
58
|
+
* param the TS Spec declares), matching [com.rezaul.printerkit.BluetoothPrinter]'s own
|
|
59
|
+
* single-params-object functions on the native side.
|
|
35
60
|
*/
|
|
36
61
|
class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
37
62
|
NativeReactNativePrinterKitSpec(reactContext) {
|
|
@@ -126,11 +151,16 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
126
151
|
return result
|
|
127
152
|
}
|
|
128
153
|
|
|
129
|
-
override fun connectPrinter(
|
|
154
|
+
override fun connectPrinter(params: ReadableMap, promise: Promise) {
|
|
155
|
+
val address = params.getString("address")
|
|
156
|
+
if (address == null) {
|
|
157
|
+
promise.reject("ERROR", "address is required")
|
|
158
|
+
return
|
|
159
|
+
}
|
|
130
160
|
withService { service ->
|
|
131
161
|
executor.execute {
|
|
132
162
|
try {
|
|
133
|
-
promise.resolve(service.connectAndKeepAlive(address))
|
|
163
|
+
promise.resolve(service.connectAndKeepAlive(ConnectPrinterParams(address)))
|
|
134
164
|
} catch (e: Exception) {
|
|
135
165
|
promise.reject("ERROR", e.message)
|
|
136
166
|
}
|
|
@@ -176,11 +206,16 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
176
206
|
}
|
|
177
207
|
}
|
|
178
208
|
|
|
179
|
-
override fun printText(
|
|
209
|
+
override fun printText(params: ReadableMap, promise: Promise) {
|
|
210
|
+
val text = params.getString("text")
|
|
211
|
+
if (text == null) {
|
|
212
|
+
promise.reject("ERROR", "text is required")
|
|
213
|
+
return
|
|
214
|
+
}
|
|
180
215
|
withService { service ->
|
|
181
216
|
executor.execute {
|
|
182
217
|
try {
|
|
183
|
-
service.printer.printText(text, (feedLines
|
|
218
|
+
service.printer.printText(PrintTextParams(text, params.optInt("feedLines", 3)))
|
|
184
219
|
promise.resolve(null)
|
|
185
220
|
} catch (e: Exception) {
|
|
186
221
|
promise.reject("ERROR", e.message)
|
|
@@ -189,11 +224,24 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
189
224
|
}
|
|
190
225
|
}
|
|
191
226
|
|
|
192
|
-
override fun printImage(
|
|
227
|
+
override fun printImage(params: ReadableMap, promise: Promise) {
|
|
228
|
+
val imagePath = params.getString("imagePath")
|
|
229
|
+
if (imagePath == null) {
|
|
230
|
+
promise.reject("ERROR", "imagePath is required")
|
|
231
|
+
return
|
|
232
|
+
}
|
|
193
233
|
withService { service ->
|
|
194
234
|
executor.execute {
|
|
195
235
|
try {
|
|
196
|
-
service.printer.printImageFile(
|
|
236
|
+
service.printer.printImageFile(
|
|
237
|
+
PrintImageFileParams(
|
|
238
|
+
imagePath = imagePath,
|
|
239
|
+
printerWidthDots = params.optInt("printerWidthDots", 384),
|
|
240
|
+
feedLines = params.optInt("feedLines", 3),
|
|
241
|
+
bandHeightDots = params.optInt("bandHeightDots", 16),
|
|
242
|
+
bandDelayMs = params.optLong("bandDelayMs", 60L)
|
|
243
|
+
)
|
|
244
|
+
)
|
|
197
245
|
promise.resolve(null)
|
|
198
246
|
} catch (e: Exception) {
|
|
199
247
|
promise.reject("ERROR", e.message)
|
|
@@ -202,11 +250,24 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
202
250
|
}
|
|
203
251
|
}
|
|
204
252
|
|
|
205
|
-
override fun printImageBase64(
|
|
253
|
+
override fun printImageBase64(params: ReadableMap, promise: Promise) {
|
|
254
|
+
val base64 = params.getString("base64")
|
|
255
|
+
if (base64 == null) {
|
|
256
|
+
promise.reject("ERROR", "base64 is required")
|
|
257
|
+
return
|
|
258
|
+
}
|
|
206
259
|
withService { service ->
|
|
207
260
|
executor.execute {
|
|
208
261
|
try {
|
|
209
|
-
service.printer.printImageBase64(
|
|
262
|
+
service.printer.printImageBase64(
|
|
263
|
+
PrintImageBase64Params(
|
|
264
|
+
base64 = base64,
|
|
265
|
+
printerWidthDots = params.optInt("printerWidthDots", 384),
|
|
266
|
+
feedLines = params.optInt("feedLines", 3),
|
|
267
|
+
bandHeightDots = params.optInt("bandHeightDots", 16),
|
|
268
|
+
bandDelayMs = params.optLong("bandDelayMs", 60L)
|
|
269
|
+
)
|
|
270
|
+
)
|
|
210
271
|
promise.resolve(null)
|
|
211
272
|
} catch (e: Exception) {
|
|
212
273
|
promise.reject("ERROR", e.message)
|
|
@@ -215,12 +276,28 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
215
276
|
}
|
|
216
277
|
}
|
|
217
278
|
|
|
218
|
-
override fun pdfToImage(
|
|
279
|
+
override fun pdfToImage(params: ReadableMap, promise: Promise) {
|
|
280
|
+
val pdfPath = params.getString("pdfPath")
|
|
281
|
+
if (pdfPath == null) {
|
|
282
|
+
promise.reject("ERROR", "pdfPath is required")
|
|
283
|
+
return
|
|
284
|
+
}
|
|
219
285
|
withService { service ->
|
|
220
286
|
executor.execute {
|
|
221
287
|
try {
|
|
222
|
-
val
|
|
223
|
-
|
|
288
|
+
val imageType = if (params.getString("imageType") == "JPEG") {
|
|
289
|
+
PrinterImageType.JPEG
|
|
290
|
+
} else {
|
|
291
|
+
PrinterImageType.PNG
|
|
292
|
+
}
|
|
293
|
+
val path = service.printer.pdfToImage(
|
|
294
|
+
PdfToImageParams(
|
|
295
|
+
pdfPath = pdfPath,
|
|
296
|
+
imageType = imageType,
|
|
297
|
+
page = params.optInt("page", 0),
|
|
298
|
+
targetWidthPx = params.optIntOrNull("targetWidthPx")
|
|
299
|
+
)
|
|
300
|
+
)
|
|
224
301
|
promise.resolve(path)
|
|
225
302
|
} catch (e: Exception) {
|
|
226
303
|
promise.reject("ERROR", e.message)
|
|
@@ -229,11 +306,25 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
229
306
|
}
|
|
230
307
|
}
|
|
231
308
|
|
|
232
|
-
override fun printPdf(
|
|
309
|
+
override fun printPdf(params: ReadableMap, promise: Promise) {
|
|
310
|
+
val pdfPath = params.getString("pdfPath")
|
|
311
|
+
if (pdfPath == null) {
|
|
312
|
+
promise.reject("ERROR", "pdfPath is required")
|
|
313
|
+
return
|
|
314
|
+
}
|
|
233
315
|
withService { service ->
|
|
234
316
|
executor.execute {
|
|
235
317
|
try {
|
|
236
|
-
service.printer.printPdf(
|
|
318
|
+
service.printer.printPdf(
|
|
319
|
+
PrintPdfParams(
|
|
320
|
+
pdfPath = pdfPath,
|
|
321
|
+
printerWidthDots = params.optInt("printerWidthDots", 384),
|
|
322
|
+
page = params.optInt("page", 0),
|
|
323
|
+
feedLines = params.optInt("feedLines", 3),
|
|
324
|
+
bandHeightDots = params.optInt("bandHeightDots", 16),
|
|
325
|
+
bandDelayMs = params.optLong("bandDelayMs", 60L)
|
|
326
|
+
)
|
|
327
|
+
)
|
|
237
328
|
promise.resolve(null)
|
|
238
329
|
} catch (e: Exception) {
|
|
239
330
|
promise.reject("ERROR", e.message)
|
|
@@ -242,34 +333,43 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
242
333
|
}
|
|
243
334
|
}
|
|
244
335
|
|
|
245
|
-
override fun htmlToPdf(
|
|
336
|
+
override fun htmlToPdf(params: ReadableMap, promise: Promise) {
|
|
337
|
+
val html = params.getString("html")
|
|
338
|
+
if (html == null) {
|
|
339
|
+
promise.reject("ERROR", "html is required")
|
|
340
|
+
return
|
|
341
|
+
}
|
|
246
342
|
withService { service ->
|
|
247
343
|
service.printer.htmlToPdf(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
344
|
+
HtmlToPdfParams(
|
|
345
|
+
html = html,
|
|
346
|
+
pageWidthDp = params.optInt("pageWidthDp", 412),
|
|
347
|
+
heightDp = params.optIntOrNull("heightDp"),
|
|
348
|
+
minPageHeightDp = params.optInt("minPageHeightDp", 1000)
|
|
349
|
+
)
|
|
252
350
|
) { path ->
|
|
253
351
|
promise.resolve(path)
|
|
254
352
|
}
|
|
255
353
|
}
|
|
256
354
|
}
|
|
257
355
|
|
|
258
|
-
override fun printHtml(
|
|
259
|
-
html
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
promise: Promise
|
|
265
|
-
) {
|
|
356
|
+
override fun printHtml(params: ReadableMap, promise: Promise) {
|
|
357
|
+
val html = params.getString("html")
|
|
358
|
+
if (html == null) {
|
|
359
|
+
promise.reject("ERROR", "html is required")
|
|
360
|
+
return
|
|
361
|
+
}
|
|
266
362
|
withService { service ->
|
|
267
363
|
service.printer.printHtml(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
364
|
+
PrintHtmlParams(
|
|
365
|
+
html = html,
|
|
366
|
+
printerWidthDots = params.optInt("printerWidthDots", 384),
|
|
367
|
+
pageWidthDp = params.optInt("pageWidthDp", 412),
|
|
368
|
+
heightDp = params.optIntOrNull("heightDp"),
|
|
369
|
+
minPageHeightDp = params.optInt("minPageHeightDp", 1000),
|
|
370
|
+
bandHeightDots = params.optInt("bandHeightDots", 16),
|
|
371
|
+
bandDelayMs = params.optLong("bandDelayMs", 60L)
|
|
372
|
+
)
|
|
273
373
|
) { ok ->
|
|
274
374
|
promise.resolve(ok)
|
|
275
375
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","Platform","getModule","OS","getEnforcing"],"sourceRoot":"../../src","sources":["NativeReactNativePrinterKit.ts"],"mappings":";;AAAA,SAASA,mBAAmB,EAAoBC,QAAQ,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","Platform","getModule","OS","getEnforcing"],"sourceRoot":"../../src","sources":["NativeReactNativePrinterKit.ts"],"mappings":";;AAAA,SAASA,mBAAmB,EAAoBC,QAAQ,QAAQ,cAAc;AAqK9E,SAASC,SAASA,CAAA,EAAS;EACzB,OAAOD,QAAQ,CAACE,EAAE,KAAK,SAAS,GAC5BH,mBAAmB,CAACI,YAAY,CAAO,uBAAuB,CAAC,GAC9D,CAAC,CAAU;AAClB;AAEA,eAAeF,SAAS,CAAC,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -28,8 +28,8 @@ export function getBondedBluetoothPrinters() {
|
|
|
28
28
|
* survives the app being swiped from Recents, and is reconnected to
|
|
29
29
|
* automatically the next time the app starts.
|
|
30
30
|
*/
|
|
31
|
-
export function connectPrinter(
|
|
32
|
-
return ReactNativePrinterKit.connectPrinter(
|
|
31
|
+
export function connectPrinter(params) {
|
|
32
|
+
return ReactNativePrinterKit.connectPrinter(params);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -57,53 +57,53 @@ export function getConnectedPrinter() {
|
|
|
57
57
|
* Print raw text using the printer's built-in font (ASCII only - use
|
|
58
58
|
* printHtml() for Bangla or other non-Latin scripts).
|
|
59
59
|
*/
|
|
60
|
-
export function printText(
|
|
61
|
-
return ReactNativePrinterKit.printText(
|
|
60
|
+
export function printText(params) {
|
|
61
|
+
return ReactNativePrinterKit.printText(params);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Print an image file as an ESC/POS raster image.
|
|
66
|
-
*
|
|
66
|
+
* `printerWidthDots`: 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
67
67
|
*/
|
|
68
|
-
export function printImage(
|
|
69
|
-
return ReactNativePrinterKit.printImage(
|
|
68
|
+
export function printImage(params) {
|
|
69
|
+
return ReactNativePrinterKit.printImage(params);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Print a base64-encoded image as an ESC/POS raster image.
|
|
74
74
|
*/
|
|
75
|
-
export function printImageBase64(
|
|
76
|
-
return ReactNativePrinterKit.printImageBase64(
|
|
75
|
+
export function printImageBase64(params) {
|
|
76
|
+
return ReactNativePrinterKit.printImageBase64(params);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* Render a page of a PDF file to an image file. Returns the image path.
|
|
81
81
|
*/
|
|
82
|
-
export function pdfToImage(
|
|
83
|
-
return ReactNativePrinterKit.pdfToImage(
|
|
82
|
+
export function pdfToImage(params) {
|
|
83
|
+
return ReactNativePrinterKit.pdfToImage(params);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* Render a page of a PDF to an image, then print it.
|
|
88
88
|
*/
|
|
89
|
-
export function printPdf(
|
|
90
|
-
return ReactNativePrinterKit.printPdf(
|
|
89
|
+
export function printPdf(params) {
|
|
90
|
+
return ReactNativePrinterKit.printPdf(params);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* Render HTML to a PDF file and return its path, or null on failure. See
|
|
95
95
|
* NativeReactNativePrinterKit's Spec for what pageWidthDp/heightDp/minPageHeightDp control.
|
|
96
96
|
*/
|
|
97
|
-
export function htmlToPdf(
|
|
98
|
-
return ReactNativePrinterKit.htmlToPdf(
|
|
97
|
+
export function htmlToPdf(params) {
|
|
98
|
+
return ReactNativePrinterKit.htmlToPdf(params);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Full pipeline: render HTML to PDF, then print it - the way to print Bangla
|
|
103
103
|
* (or other non-Latin) text or any real HTML/CSS layout.
|
|
104
104
|
*/
|
|
105
|
-
export function printHtml(
|
|
106
|
-
return ReactNativePrinterKit.printHtml(
|
|
105
|
+
export function printHtml(params) {
|
|
106
|
+
return ReactNativePrinterKit.printHtml(params);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// Export types
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ReactNativePrinterKit","hasBluetoothPermission","requestBluetoothPermission","getBondedBluetoothPrinters","connectPrinter","
|
|
1
|
+
{"version":3,"names":["ReactNativePrinterKit","hasBluetoothPermission","requestBluetoothPermission","getBondedBluetoothPrinters","connectPrinter","params","disconnectPrinter","isConnectedPrinter","getConnectedPrinter","printText","printImage","printImageBase64","pdfToImage","printPdf","htmlToPdf","printHtml"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,qBAAqB,MAWrB,kCAA+B;;AAEtC;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CAAA,EAAY;EAChD,OAAOD,qBAAqB,CAACC,sBAAsB,CAAC,CAAC;AACvD;;AAEA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CAAA,EAAqB;EAC7D,OAAOF,qBAAqB,CAACE,0BAA0B,CAAC,CAAC;AAC3D;;AAEA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CAAA,EAA6B;EACrE,OAAOH,qBAAqB,CAACG,0BAA0B,CAAC,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACC,MAA4B,EAAoB;EAC7E,OAAOL,qBAAqB,CAACI,cAAc,CAACC,MAAM,CAAC;AACrD;;AAEA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAA,EAAkB;EACjD,OAAON,qBAAqB,CAACM,iBAAiB,CAAC,CAAC;AAClD;;AAEA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAA,EAAqB;EACrD,OAAOP,qBAAqB,CAACO,kBAAkB,CAAC,CAAC;AACnD;;AAEA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAAA,EAA2C;EAC5E,OAAOR,qBAAqB,CAACQ,mBAAmB,CAAC,CAAC;AACpD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CAACJ,MAAuB,EAAiB;EAChE,OAAOL,qBAAqB,CAACS,SAAS,CAACJ,MAAM,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASK,UAAUA,CAACL,MAAwB,EAAiB;EAClE,OAAOL,qBAAqB,CAACU,UAAU,CAACL,MAAM,CAAC;AACjD;;AAEA;AACA;AACA;AACA,OAAO,SAASM,gBAAgBA,CAACN,MAA8B,EAAiB;EAC9E,OAAOL,qBAAqB,CAACW,gBAAgB,CAACN,MAAM,CAAC;AACvD;;AAEA;AACA;AACA;AACA,OAAO,SAASO,UAAUA,CAACP,MAAwB,EAAmB;EACpE,OAAOL,qBAAqB,CAACY,UAAU,CAACP,MAAM,CAAC;AACjD;;AAEA;AACA;AACA;AACA,OAAO,SAASQ,QAAQA,CAACR,MAAsB,EAAiB;EAC9D,OAAOL,qBAAqB,CAACa,QAAQ,CAACR,MAAM,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASS,SAASA,CAACT,MAAuB,EAA0B;EACzE,OAAOL,qBAAqB,CAACc,SAAS,CAACT,MAAM,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASU,SAASA,CAACV,MAAuB,EAAoB;EACnE,OAAOL,qBAAqB,CAACe,SAAS,CAACV,MAAM,CAAC;AAChD;;AAEA;;AAcA;AACA,eAAeL,qBAAqB","ignoreList":[]}
|
|
@@ -4,6 +4,64 @@ export type BluetoothPrinterDevice = {
|
|
|
4
4
|
address: string;
|
|
5
5
|
};
|
|
6
6
|
export type PrinterImageType = 'PNG' | 'JPEG';
|
|
7
|
+
export type ConnectPrinterParams = {
|
|
8
|
+
address: string;
|
|
9
|
+
};
|
|
10
|
+
export type PrintTextParams = {
|
|
11
|
+
text: string;
|
|
12
|
+
feedLines?: number;
|
|
13
|
+
};
|
|
14
|
+
export type PrintImageParams = {
|
|
15
|
+
imagePath: string;
|
|
16
|
+
printerWidthDots?: number;
|
|
17
|
+
feedLines?: number;
|
|
18
|
+
/** Height (in dots) of each raster band sent to the printer. Lower this for printers with a small receive buffer that drop or garble large images. Default 16. */
|
|
19
|
+
bandHeightDots?: number;
|
|
20
|
+
/** Pause (ms) between raster bands, giving the printer time to catch up. Default 60. */
|
|
21
|
+
bandDelayMs?: number;
|
|
22
|
+
};
|
|
23
|
+
export type PrintImageBase64Params = {
|
|
24
|
+
base64: string;
|
|
25
|
+
printerWidthDots?: number;
|
|
26
|
+
feedLines?: number;
|
|
27
|
+
/** See PrintImageParams.bandHeightDots. */
|
|
28
|
+
bandHeightDots?: number;
|
|
29
|
+
/** See PrintImageParams.bandDelayMs. */
|
|
30
|
+
bandDelayMs?: number;
|
|
31
|
+
};
|
|
32
|
+
export type PdfToImageParams = {
|
|
33
|
+
pdfPath: string;
|
|
34
|
+
imageType?: PrinterImageType;
|
|
35
|
+
page?: number;
|
|
36
|
+
targetWidthPx?: number;
|
|
37
|
+
};
|
|
38
|
+
export type PrintPdfParams = {
|
|
39
|
+
pdfPath: string;
|
|
40
|
+
printerWidthDots?: number;
|
|
41
|
+
page?: number;
|
|
42
|
+
feedLines?: number;
|
|
43
|
+
/** See PrintImageParams.bandHeightDots. */
|
|
44
|
+
bandHeightDots?: number;
|
|
45
|
+
/** See PrintImageParams.bandDelayMs. */
|
|
46
|
+
bandDelayMs?: number;
|
|
47
|
+
};
|
|
48
|
+
export type HtmlToPdfParams = {
|
|
49
|
+
html: string;
|
|
50
|
+
pageWidthDp?: number;
|
|
51
|
+
heightDp?: number;
|
|
52
|
+
minPageHeightDp?: number;
|
|
53
|
+
};
|
|
54
|
+
export type PrintHtmlParams = {
|
|
55
|
+
html: string;
|
|
56
|
+
printerWidthDots?: number;
|
|
57
|
+
pageWidthDp?: number;
|
|
58
|
+
heightDp?: number;
|
|
59
|
+
minPageHeightDp?: number;
|
|
60
|
+
/** See PrintImageParams.bandHeightDots. */
|
|
61
|
+
bandHeightDots?: number;
|
|
62
|
+
/** See PrintImageParams.bandDelayMs. */
|
|
63
|
+
bandDelayMs?: number;
|
|
64
|
+
};
|
|
7
65
|
export interface Spec extends TurboModule {
|
|
8
66
|
/**
|
|
9
67
|
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
@@ -25,7 +83,7 @@ export interface Spec extends TurboModule {
|
|
|
25
83
|
* app reconnects automatically next time it's opened (see the README's
|
|
26
84
|
* "Persistent connection" section).
|
|
27
85
|
*/
|
|
28
|
-
connectPrinter(
|
|
86
|
+
connectPrinter(params: ConnectPrinterParams): Promise<boolean>;
|
|
29
87
|
/**
|
|
30
88
|
* Closes the current printer connection, if any, and forgets it for auto-reconnect.
|
|
31
89
|
*/
|
|
@@ -42,43 +100,43 @@ export interface Spec extends TurboModule {
|
|
|
42
100
|
* Print raw text using the printer's built-in font. ASCII only - not
|
|
43
101
|
* suitable for Bangla or other non-Latin scripts, use printHtml() instead.
|
|
44
102
|
*/
|
|
45
|
-
printText(
|
|
103
|
+
printText(params: PrintTextParams): Promise<void>;
|
|
46
104
|
/**
|
|
47
105
|
* Print an image file as a dithered ESC/POS raster image.
|
|
48
|
-
*
|
|
106
|
+
* `printerWidthDots`: 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
49
107
|
*/
|
|
50
|
-
printImage(
|
|
108
|
+
printImage(params: PrintImageParams): Promise<void>;
|
|
51
109
|
/**
|
|
52
110
|
* Print a base64-encoded image as a dithered ESC/POS raster image.
|
|
53
111
|
*/
|
|
54
|
-
printImageBase64(
|
|
112
|
+
printImageBase64(params: PrintImageBase64Params): Promise<void>;
|
|
55
113
|
/**
|
|
56
114
|
* Renders a page of a PDF file to an image file (via Android's PdfRenderer)
|
|
57
115
|
* and returns the image's absolute path.
|
|
58
116
|
*/
|
|
59
|
-
pdfToImage(
|
|
117
|
+
pdfToImage(params: PdfToImageParams): Promise<string>;
|
|
60
118
|
/**
|
|
61
119
|
* Renders a page of a PDF to an image, then prints it.
|
|
62
120
|
*/
|
|
63
|
-
printPdf(
|
|
121
|
+
printPdf(params: PrintPdfParams): Promise<void>;
|
|
64
122
|
/**
|
|
65
123
|
* Renders HTML to a PDF file using an off-screen WebView (no external
|
|
66
124
|
* library) and returns the PDF's absolute path, or null on failure.
|
|
67
125
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
126
|
+
* `pageWidthDp` is the layout width the HTML is rendered at - controls how
|
|
127
|
+
* large the content looks relative to the page, independent of the final
|
|
128
|
+
* printed width (`printerWidthDots` on printHtml/printPdf downscales it).
|
|
129
|
+
* `heightDp`, if set, forces the page to exactly this height (dp) instead
|
|
130
|
+
* of auto-measuring the HTML's real content height. `minPageHeightDp` is
|
|
131
|
+
* ignored if `heightDp` is set - a height floor (dp) for auto-measured
|
|
132
|
+
* content, only relevant for very short/empty HTML.
|
|
75
133
|
*/
|
|
76
|
-
htmlToPdf(
|
|
134
|
+
htmlToPdf(params: HtmlToPdfParams): Promise<string | null>;
|
|
77
135
|
/**
|
|
78
136
|
* Full pipeline: htmlToPdf -> printPdf, in one call. This is how to print
|
|
79
137
|
* content with Bangla or other non-Latin text, or any real HTML/CSS layout.
|
|
80
138
|
*/
|
|
81
|
-
printHtml(
|
|
139
|
+
printHtml(params: PrintHtmlParams): Promise<boolean>;
|
|
82
140
|
}
|
|
83
141
|
declare const _default: Spec;
|
|
84
142
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeReactNativePrinterKit.d.ts","sourceRoot":"","sources":["../../../src/NativeReactNativePrinterKit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAY,MAAM,cAAc,CAAC;AAE/E,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,MAAM,CAAC;AAE9C,MAAM,
|
|
1
|
+
{"version":3,"file":"NativeReactNativePrinterKit.d.ts","sourceRoot":"","sources":["../../../src/NativeReactNativePrinterKit.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ReactNativePrinterKit, { type BluetoothPrinterDevice, type PrinterImageType } from './NativeReactNativePrinterKit.js';
|
|
1
|
+
import ReactNativePrinterKit, { type BluetoothPrinterDevice, type ConnectPrinterParams, type HtmlToPdfParams, type PdfToImageParams, type PrinterImageType, type PrintHtmlParams, type PrintImageBase64Params, type PrintImageParams, type PrintPdfParams, type PrintTextParams } from './NativeReactNativePrinterKit.js';
|
|
2
2
|
/**
|
|
3
3
|
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
4
4
|
*/
|
|
@@ -16,7 +16,7 @@ export declare function getBondedBluetoothPrinters(): BluetoothPrinterDevice[];
|
|
|
16
16
|
* survives the app being swiped from Recents, and is reconnected to
|
|
17
17
|
* automatically the next time the app starts.
|
|
18
18
|
*/
|
|
19
|
-
export declare function connectPrinter(
|
|
19
|
+
export declare function connectPrinter(params: ConnectPrinterParams): Promise<boolean>;
|
|
20
20
|
/**
|
|
21
21
|
* Disconnect from the current printer.
|
|
22
22
|
*/
|
|
@@ -33,34 +33,34 @@ export declare function getConnectedPrinter(): Promise<BluetoothPrinterDevice |
|
|
|
33
33
|
* Print raw text using the printer's built-in font (ASCII only - use
|
|
34
34
|
* printHtml() for Bangla or other non-Latin scripts).
|
|
35
35
|
*/
|
|
36
|
-
export declare function printText(
|
|
36
|
+
export declare function printText(params: PrintTextParams): Promise<void>;
|
|
37
37
|
/**
|
|
38
38
|
* Print an image file as an ESC/POS raster image.
|
|
39
|
-
*
|
|
39
|
+
* `printerWidthDots`: 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
40
40
|
*/
|
|
41
|
-
export declare function printImage(
|
|
41
|
+
export declare function printImage(params: PrintImageParams): Promise<void>;
|
|
42
42
|
/**
|
|
43
43
|
* Print a base64-encoded image as an ESC/POS raster image.
|
|
44
44
|
*/
|
|
45
|
-
export declare function printImageBase64(
|
|
45
|
+
export declare function printImageBase64(params: PrintImageBase64Params): Promise<void>;
|
|
46
46
|
/**
|
|
47
47
|
* Render a page of a PDF file to an image file. Returns the image path.
|
|
48
48
|
*/
|
|
49
|
-
export declare function pdfToImage(
|
|
49
|
+
export declare function pdfToImage(params: PdfToImageParams): Promise<string>;
|
|
50
50
|
/**
|
|
51
51
|
* Render a page of a PDF to an image, then print it.
|
|
52
52
|
*/
|
|
53
|
-
export declare function printPdf(
|
|
53
|
+
export declare function printPdf(params: PrintPdfParams): Promise<void>;
|
|
54
54
|
/**
|
|
55
55
|
* Render HTML to a PDF file and return its path, or null on failure. See
|
|
56
56
|
* NativeReactNativePrinterKit's Spec for what pageWidthDp/heightDp/minPageHeightDp control.
|
|
57
57
|
*/
|
|
58
|
-
export declare function htmlToPdf(
|
|
58
|
+
export declare function htmlToPdf(params: HtmlToPdfParams): Promise<string | null>;
|
|
59
59
|
/**
|
|
60
60
|
* Full pipeline: render HTML to PDF, then print it - the way to print Bangla
|
|
61
61
|
* (or other non-Latin) text or any real HTML/CSS layout.
|
|
62
62
|
*/
|
|
63
|
-
export declare function printHtml(
|
|
64
|
-
export type { BluetoothPrinterDevice, PrinterImageType };
|
|
63
|
+
export declare function printHtml(params: PrintHtmlParams): Promise<boolean>;
|
|
64
|
+
export type { BluetoothPrinterDevice, ConnectPrinterParams, HtmlToPdfParams, PdfToImageParams, PrinterImageType, PrintHtmlParams, PrintImageBase64Params, PrintImageParams, PrintPdfParams, PrintTextParams, };
|
|
65
65
|
export default ReactNativePrinterKit;
|
|
66
66
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,EAAE,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,EAAE,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,kCAA+B,CAAC;AAEvC;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,OAAO,CAAC,OAAO,CAAC,CAE7D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,sBAAsB,EAAE,CAErE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,CAE7E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEjD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAErD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAE5E;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAElE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAEpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAEzE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnE;AAGD,YAAY,EACV,sBAAsB,EACtB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,CAAC;AAGF,eAAe,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rejaul/react-native-printer-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Direct Bluetooth POS/thermal (ESC/POS) printer integration for React Native on Android — print raw text, images, PDFs, and full HTML/CSS content including Bangla and other non-Latin scripts.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -7,6 +7,72 @@ export type BluetoothPrinterDevice = {
|
|
|
7
7
|
|
|
8
8
|
export type PrinterImageType = 'PNG' | 'JPEG';
|
|
9
9
|
|
|
10
|
+
export type ConnectPrinterParams = {
|
|
11
|
+
address: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type PrintTextParams = {
|
|
15
|
+
text: string;
|
|
16
|
+
feedLines?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type PrintImageParams = {
|
|
20
|
+
imagePath: string;
|
|
21
|
+
printerWidthDots?: number;
|
|
22
|
+
feedLines?: number;
|
|
23
|
+
/** Height (in dots) of each raster band sent to the printer. Lower this for printers with a small receive buffer that drop or garble large images. Default 16. */
|
|
24
|
+
bandHeightDots?: number;
|
|
25
|
+
/** Pause (ms) between raster bands, giving the printer time to catch up. Default 60. */
|
|
26
|
+
bandDelayMs?: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type PrintImageBase64Params = {
|
|
30
|
+
base64: string;
|
|
31
|
+
printerWidthDots?: number;
|
|
32
|
+
feedLines?: number;
|
|
33
|
+
/** See PrintImageParams.bandHeightDots. */
|
|
34
|
+
bandHeightDots?: number;
|
|
35
|
+
/** See PrintImageParams.bandDelayMs. */
|
|
36
|
+
bandDelayMs?: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type PdfToImageParams = {
|
|
40
|
+
pdfPath: string;
|
|
41
|
+
imageType?: PrinterImageType;
|
|
42
|
+
page?: number;
|
|
43
|
+
targetWidthPx?: number;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type PrintPdfParams = {
|
|
47
|
+
pdfPath: string;
|
|
48
|
+
printerWidthDots?: number;
|
|
49
|
+
page?: number;
|
|
50
|
+
feedLines?: number;
|
|
51
|
+
/** See PrintImageParams.bandHeightDots. */
|
|
52
|
+
bandHeightDots?: number;
|
|
53
|
+
/** See PrintImageParams.bandDelayMs. */
|
|
54
|
+
bandDelayMs?: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type HtmlToPdfParams = {
|
|
58
|
+
html: string;
|
|
59
|
+
pageWidthDp?: number;
|
|
60
|
+
heightDp?: number;
|
|
61
|
+
minPageHeightDp?: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type PrintHtmlParams = {
|
|
65
|
+
html: string;
|
|
66
|
+
printerWidthDots?: number;
|
|
67
|
+
pageWidthDp?: number;
|
|
68
|
+
heightDp?: number;
|
|
69
|
+
minPageHeightDp?: number;
|
|
70
|
+
/** See PrintImageParams.bandHeightDots. */
|
|
71
|
+
bandHeightDots?: number;
|
|
72
|
+
/** See PrintImageParams.bandDelayMs. */
|
|
73
|
+
bandDelayMs?: number;
|
|
74
|
+
};
|
|
75
|
+
|
|
10
76
|
export interface Spec extends TurboModule {
|
|
11
77
|
/**
|
|
12
78
|
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
@@ -31,7 +97,7 @@ export interface Spec extends TurboModule {
|
|
|
31
97
|
* app reconnects automatically next time it's opened (see the README's
|
|
32
98
|
* "Persistent connection" section).
|
|
33
99
|
*/
|
|
34
|
-
connectPrinter(
|
|
100
|
+
connectPrinter(params: ConnectPrinterParams): Promise<boolean>;
|
|
35
101
|
|
|
36
102
|
/**
|
|
37
103
|
* Closes the current printer connection, if any, and forgets it for auto-reconnect.
|
|
@@ -52,78 +118,49 @@ export interface Spec extends TurboModule {
|
|
|
52
118
|
* Print raw text using the printer's built-in font. ASCII only - not
|
|
53
119
|
* suitable for Bangla or other non-Latin scripts, use printHtml() instead.
|
|
54
120
|
*/
|
|
55
|
-
printText(
|
|
121
|
+
printText(params: PrintTextParams): Promise<void>;
|
|
56
122
|
|
|
57
123
|
/**
|
|
58
124
|
* Print an image file as a dithered ESC/POS raster image.
|
|
59
|
-
*
|
|
125
|
+
* `printerWidthDots`: 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
60
126
|
*/
|
|
61
|
-
printImage(
|
|
62
|
-
imagePath: string,
|
|
63
|
-
printerWidthDots?: number,
|
|
64
|
-
feedLines?: number
|
|
65
|
-
): Promise<void>;
|
|
127
|
+
printImage(params: PrintImageParams): Promise<void>;
|
|
66
128
|
|
|
67
129
|
/**
|
|
68
130
|
* Print a base64-encoded image as a dithered ESC/POS raster image.
|
|
69
131
|
*/
|
|
70
|
-
printImageBase64(
|
|
71
|
-
base64: string,
|
|
72
|
-
printerWidthDots?: number,
|
|
73
|
-
feedLines?: number
|
|
74
|
-
): Promise<void>;
|
|
132
|
+
printImageBase64(params: PrintImageBase64Params): Promise<void>;
|
|
75
133
|
|
|
76
134
|
/**
|
|
77
135
|
* Renders a page of a PDF file to an image file (via Android's PdfRenderer)
|
|
78
136
|
* and returns the image's absolute path.
|
|
79
137
|
*/
|
|
80
|
-
pdfToImage(
|
|
81
|
-
pdfPath: string,
|
|
82
|
-
imageType?: PrinterImageType,
|
|
83
|
-
page?: number,
|
|
84
|
-
targetWidthPx?: number
|
|
85
|
-
): Promise<string>;
|
|
138
|
+
pdfToImage(params: PdfToImageParams): Promise<string>;
|
|
86
139
|
|
|
87
140
|
/**
|
|
88
141
|
* Renders a page of a PDF to an image, then prints it.
|
|
89
142
|
*/
|
|
90
|
-
printPdf(
|
|
91
|
-
pdfPath: string,
|
|
92
|
-
printerWidthDots?: number,
|
|
93
|
-
page?: number,
|
|
94
|
-
feedLines?: number
|
|
95
|
-
): Promise<void>;
|
|
143
|
+
printPdf(params: PrintPdfParams): Promise<void>;
|
|
96
144
|
|
|
97
145
|
/**
|
|
98
146
|
* Renders HTML to a PDF file using an off-screen WebView (no external
|
|
99
147
|
* library) and returns the PDF's absolute path, or null on failure.
|
|
100
148
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
149
|
+
* `pageWidthDp` is the layout width the HTML is rendered at - controls how
|
|
150
|
+
* large the content looks relative to the page, independent of the final
|
|
151
|
+
* printed width (`printerWidthDots` on printHtml/printPdf downscales it).
|
|
152
|
+
* `heightDp`, if set, forces the page to exactly this height (dp) instead
|
|
153
|
+
* of auto-measuring the HTML's real content height. `minPageHeightDp` is
|
|
154
|
+
* ignored if `heightDp` is set - a height floor (dp) for auto-measured
|
|
155
|
+
* content, only relevant for very short/empty HTML.
|
|
108
156
|
*/
|
|
109
|
-
htmlToPdf(
|
|
110
|
-
html: string,
|
|
111
|
-
pageWidthDp?: number,
|
|
112
|
-
heightDp?: number,
|
|
113
|
-
minPageHeightDp?: number
|
|
114
|
-
): Promise<string | null>;
|
|
157
|
+
htmlToPdf(params: HtmlToPdfParams): Promise<string | null>;
|
|
115
158
|
|
|
116
159
|
/**
|
|
117
160
|
* Full pipeline: htmlToPdf -> printPdf, in one call. This is how to print
|
|
118
161
|
* content with Bangla or other non-Latin text, or any real HTML/CSS layout.
|
|
119
162
|
*/
|
|
120
|
-
printHtml(
|
|
121
|
-
html: string,
|
|
122
|
-
printerWidthDots?: number,
|
|
123
|
-
pageWidthDp?: number,
|
|
124
|
-
heightDp?: number,
|
|
125
|
-
minPageHeightDp?: number
|
|
126
|
-
): Promise<boolean>;
|
|
163
|
+
printHtml(params: PrintHtmlParams): Promise<boolean>;
|
|
127
164
|
}
|
|
128
165
|
|
|
129
166
|
function getModule(): Spec {
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import ReactNativePrinterKit, {
|
|
2
2
|
type BluetoothPrinterDevice,
|
|
3
|
+
type ConnectPrinterParams,
|
|
4
|
+
type HtmlToPdfParams,
|
|
5
|
+
type PdfToImageParams,
|
|
3
6
|
type PrinterImageType,
|
|
7
|
+
type PrintHtmlParams,
|
|
8
|
+
type PrintImageBase64Params,
|
|
9
|
+
type PrintImageParams,
|
|
10
|
+
type PrintPdfParams,
|
|
11
|
+
type PrintTextParams,
|
|
4
12
|
} from './NativeReactNativePrinterKit';
|
|
5
13
|
|
|
6
14
|
/**
|
|
@@ -29,8 +37,8 @@ export function getBondedBluetoothPrinters(): BluetoothPrinterDevice[] {
|
|
|
29
37
|
* survives the app being swiped from Recents, and is reconnected to
|
|
30
38
|
* automatically the next time the app starts.
|
|
31
39
|
*/
|
|
32
|
-
export function connectPrinter(
|
|
33
|
-
return ReactNativePrinterKit.connectPrinter(
|
|
40
|
+
export function connectPrinter(params: ConnectPrinterParams): Promise<boolean> {
|
|
41
|
+
return ReactNativePrinterKit.connectPrinter(params);
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
/**
|
|
@@ -58,92 +66,68 @@ export function getConnectedPrinter(): Promise<BluetoothPrinterDevice | null> {
|
|
|
58
66
|
* Print raw text using the printer's built-in font (ASCII only - use
|
|
59
67
|
* printHtml() for Bangla or other non-Latin scripts).
|
|
60
68
|
*/
|
|
61
|
-
export function printText(
|
|
62
|
-
return ReactNativePrinterKit.printText(
|
|
69
|
+
export function printText(params: PrintTextParams): Promise<void> {
|
|
70
|
+
return ReactNativePrinterKit.printText(params);
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
/**
|
|
66
74
|
* Print an image file as an ESC/POS raster image.
|
|
67
|
-
*
|
|
75
|
+
* `printerWidthDots`: 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
68
76
|
*/
|
|
69
|
-
export function printImage(
|
|
70
|
-
|
|
71
|
-
printerWidthDots?: number,
|
|
72
|
-
feedLines?: number
|
|
73
|
-
): Promise<void> {
|
|
74
|
-
return ReactNativePrinterKit.printImage(imagePath, printerWidthDots, feedLines);
|
|
77
|
+
export function printImage(params: PrintImageParams): Promise<void> {
|
|
78
|
+
return ReactNativePrinterKit.printImage(params);
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
82
|
* Print a base64-encoded image as an ESC/POS raster image.
|
|
79
83
|
*/
|
|
80
|
-
export function printImageBase64(
|
|
81
|
-
|
|
82
|
-
printerWidthDots?: number,
|
|
83
|
-
feedLines?: number
|
|
84
|
-
): Promise<void> {
|
|
85
|
-
return ReactNativePrinterKit.printImageBase64(base64, printerWidthDots, feedLines);
|
|
84
|
+
export function printImageBase64(params: PrintImageBase64Params): Promise<void> {
|
|
85
|
+
return ReactNativePrinterKit.printImageBase64(params);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* Render a page of a PDF file to an image file. Returns the image path.
|
|
90
90
|
*/
|
|
91
|
-
export function pdfToImage(
|
|
92
|
-
|
|
93
|
-
imageType?: PrinterImageType,
|
|
94
|
-
page?: number,
|
|
95
|
-
targetWidthPx?: number
|
|
96
|
-
): Promise<string> {
|
|
97
|
-
return ReactNativePrinterKit.pdfToImage(pdfPath, imageType, page, targetWidthPx);
|
|
91
|
+
export function pdfToImage(params: PdfToImageParams): Promise<string> {
|
|
92
|
+
return ReactNativePrinterKit.pdfToImage(params);
|
|
98
93
|
}
|
|
99
94
|
|
|
100
95
|
/**
|
|
101
96
|
* Render a page of a PDF to an image, then print it.
|
|
102
97
|
*/
|
|
103
|
-
export function printPdf(
|
|
104
|
-
|
|
105
|
-
printerWidthDots?: number,
|
|
106
|
-
page?: number,
|
|
107
|
-
feedLines?: number
|
|
108
|
-
): Promise<void> {
|
|
109
|
-
return ReactNativePrinterKit.printPdf(pdfPath, printerWidthDots, page, feedLines);
|
|
98
|
+
export function printPdf(params: PrintPdfParams): Promise<void> {
|
|
99
|
+
return ReactNativePrinterKit.printPdf(params);
|
|
110
100
|
}
|
|
111
101
|
|
|
112
102
|
/**
|
|
113
103
|
* Render HTML to a PDF file and return its path, or null on failure. See
|
|
114
104
|
* NativeReactNativePrinterKit's Spec for what pageWidthDp/heightDp/minPageHeightDp control.
|
|
115
105
|
*/
|
|
116
|
-
export function htmlToPdf(
|
|
117
|
-
|
|
118
|
-
pageWidthDp?: number,
|
|
119
|
-
heightDp?: number,
|
|
120
|
-
minPageHeightDp?: number
|
|
121
|
-
): Promise<string | null> {
|
|
122
|
-
return ReactNativePrinterKit.htmlToPdf(html, pageWidthDp, heightDp, minPageHeightDp);
|
|
106
|
+
export function htmlToPdf(params: HtmlToPdfParams): Promise<string | null> {
|
|
107
|
+
return ReactNativePrinterKit.htmlToPdf(params);
|
|
123
108
|
}
|
|
124
109
|
|
|
125
110
|
/**
|
|
126
111
|
* Full pipeline: render HTML to PDF, then print it - the way to print Bangla
|
|
127
112
|
* (or other non-Latin) text or any real HTML/CSS layout.
|
|
128
113
|
*/
|
|
129
|
-
export function printHtml(
|
|
130
|
-
|
|
131
|
-
printerWidthDots?: number,
|
|
132
|
-
pageWidthDp?: number,
|
|
133
|
-
heightDp?: number,
|
|
134
|
-
minPageHeightDp?: number
|
|
135
|
-
): Promise<boolean> {
|
|
136
|
-
return ReactNativePrinterKit.printHtml(
|
|
137
|
-
html,
|
|
138
|
-
printerWidthDots,
|
|
139
|
-
pageWidthDp,
|
|
140
|
-
heightDp,
|
|
141
|
-
minPageHeightDp
|
|
142
|
-
);
|
|
114
|
+
export function printHtml(params: PrintHtmlParams): Promise<boolean> {
|
|
115
|
+
return ReactNativePrinterKit.printHtml(params);
|
|
143
116
|
}
|
|
144
117
|
|
|
145
118
|
// Export types
|
|
146
|
-
export type {
|
|
119
|
+
export type {
|
|
120
|
+
BluetoothPrinterDevice,
|
|
121
|
+
ConnectPrinterParams,
|
|
122
|
+
HtmlToPdfParams,
|
|
123
|
+
PdfToImageParams,
|
|
124
|
+
PrinterImageType,
|
|
125
|
+
PrintHtmlParams,
|
|
126
|
+
PrintImageBase64Params,
|
|
127
|
+
PrintImageParams,
|
|
128
|
+
PrintPdfParams,
|
|
129
|
+
PrintTextParams,
|
|
130
|
+
};
|
|
147
131
|
|
|
148
132
|
// Export native module
|
|
149
133
|
export default ReactNativePrinterKit;
|