@rejaul/react-native-printer-kit 0.1.0 → 0.2.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 +46 -12
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/rejaul/reactnativeprinterkit/ReactNativePrinterKitModule.kt +119 -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 +58 -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 +66 -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,38 @@ 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 = { imagePath: string; printerWidthDots?: number; feedLines?: number };
|
|
173
|
+
|
|
174
|
+
type PrintImageBase64Params = { base64: string; printerWidthDots?: number; feedLines?: number };
|
|
175
|
+
|
|
176
|
+
type PdfToImageParams = {
|
|
177
|
+
pdfPath: string;
|
|
178
|
+
imageType?: PrinterImageType;
|
|
179
|
+
page?: number;
|
|
180
|
+
targetWidthPx?: number;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
type PrintPdfParams = { pdfPath: string; printerWidthDots?: number; page?: number; feedLines?: number };
|
|
184
|
+
|
|
185
|
+
type HtmlToPdfParams = {
|
|
186
|
+
html: string;
|
|
187
|
+
pageWidthDp?: number;
|
|
188
|
+
heightDp?: number;
|
|
189
|
+
minPageHeightDp?: number;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
type PrintHtmlParams = {
|
|
193
|
+
html: string;
|
|
194
|
+
printerWidthDots?: number;
|
|
195
|
+
pageWidthDp?: number;
|
|
196
|
+
heightDp?: number;
|
|
197
|
+
minPageHeightDp?: number;
|
|
198
|
+
};
|
|
165
199
|
```
|
|
166
200
|
|
|
167
201
|
## 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,25 @@ 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
|
+
|
|
23
40
|
/**
|
|
24
41
|
* Bridges [com.rezaul.printerkit.BluetoothPrinter] to React Native.
|
|
25
42
|
*
|
|
@@ -32,6 +49,10 @@ import java.util.concurrent.Executors
|
|
|
32
49
|
* All blocking Bluetooth/PDF/image I/O runs on a single background executor, off the
|
|
33
50
|
* calling (JS) thread - also serializing printer writes, since concurrent writes to
|
|
34
51
|
* the same socket from two overlapping calls would corrupt the output.
|
|
52
|
+
*
|
|
53
|
+
* Every JS-facing method that takes data receives a single [ReadableMap] (the object
|
|
54
|
+
* param the TS Spec declares), matching [com.rezaul.printerkit.BluetoothPrinter]'s own
|
|
55
|
+
* single-params-object functions on the native side.
|
|
35
56
|
*/
|
|
36
57
|
class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
37
58
|
NativeReactNativePrinterKitSpec(reactContext) {
|
|
@@ -126,11 +147,16 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
126
147
|
return result
|
|
127
148
|
}
|
|
128
149
|
|
|
129
|
-
override fun connectPrinter(
|
|
150
|
+
override fun connectPrinter(params: ReadableMap, promise: Promise) {
|
|
151
|
+
val address = params.getString("address")
|
|
152
|
+
if (address == null) {
|
|
153
|
+
promise.reject("ERROR", "address is required")
|
|
154
|
+
return
|
|
155
|
+
}
|
|
130
156
|
withService { service ->
|
|
131
157
|
executor.execute {
|
|
132
158
|
try {
|
|
133
|
-
promise.resolve(service.connectAndKeepAlive(address))
|
|
159
|
+
promise.resolve(service.connectAndKeepAlive(ConnectPrinterParams(address)))
|
|
134
160
|
} catch (e: Exception) {
|
|
135
161
|
promise.reject("ERROR", e.message)
|
|
136
162
|
}
|
|
@@ -176,11 +202,16 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
176
202
|
}
|
|
177
203
|
}
|
|
178
204
|
|
|
179
|
-
override fun printText(
|
|
205
|
+
override fun printText(params: ReadableMap, promise: Promise) {
|
|
206
|
+
val text = params.getString("text")
|
|
207
|
+
if (text == null) {
|
|
208
|
+
promise.reject("ERROR", "text is required")
|
|
209
|
+
return
|
|
210
|
+
}
|
|
180
211
|
withService { service ->
|
|
181
212
|
executor.execute {
|
|
182
213
|
try {
|
|
183
|
-
service.printer.printText(text, (feedLines
|
|
214
|
+
service.printer.printText(PrintTextParams(text, params.optInt("feedLines", 3)))
|
|
184
215
|
promise.resolve(null)
|
|
185
216
|
} catch (e: Exception) {
|
|
186
217
|
promise.reject("ERROR", e.message)
|
|
@@ -189,11 +220,22 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
189
220
|
}
|
|
190
221
|
}
|
|
191
222
|
|
|
192
|
-
override fun printImage(
|
|
223
|
+
override fun printImage(params: ReadableMap, promise: Promise) {
|
|
224
|
+
val imagePath = params.getString("imagePath")
|
|
225
|
+
if (imagePath == null) {
|
|
226
|
+
promise.reject("ERROR", "imagePath is required")
|
|
227
|
+
return
|
|
228
|
+
}
|
|
193
229
|
withService { service ->
|
|
194
230
|
executor.execute {
|
|
195
231
|
try {
|
|
196
|
-
service.printer.printImageFile(
|
|
232
|
+
service.printer.printImageFile(
|
|
233
|
+
PrintImageFileParams(
|
|
234
|
+
imagePath = imagePath,
|
|
235
|
+
printerWidthDots = params.optInt("printerWidthDots", 384),
|
|
236
|
+
feedLines = params.optInt("feedLines", 3)
|
|
237
|
+
)
|
|
238
|
+
)
|
|
197
239
|
promise.resolve(null)
|
|
198
240
|
} catch (e: Exception) {
|
|
199
241
|
promise.reject("ERROR", e.message)
|
|
@@ -202,11 +244,22 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
202
244
|
}
|
|
203
245
|
}
|
|
204
246
|
|
|
205
|
-
override fun printImageBase64(
|
|
247
|
+
override fun printImageBase64(params: ReadableMap, promise: Promise) {
|
|
248
|
+
val base64 = params.getString("base64")
|
|
249
|
+
if (base64 == null) {
|
|
250
|
+
promise.reject("ERROR", "base64 is required")
|
|
251
|
+
return
|
|
252
|
+
}
|
|
206
253
|
withService { service ->
|
|
207
254
|
executor.execute {
|
|
208
255
|
try {
|
|
209
|
-
service.printer.printImageBase64(
|
|
256
|
+
service.printer.printImageBase64(
|
|
257
|
+
PrintImageBase64Params(
|
|
258
|
+
base64 = base64,
|
|
259
|
+
printerWidthDots = params.optInt("printerWidthDots", 384),
|
|
260
|
+
feedLines = params.optInt("feedLines", 3)
|
|
261
|
+
)
|
|
262
|
+
)
|
|
210
263
|
promise.resolve(null)
|
|
211
264
|
} catch (e: Exception) {
|
|
212
265
|
promise.reject("ERROR", e.message)
|
|
@@ -215,12 +268,28 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
215
268
|
}
|
|
216
269
|
}
|
|
217
270
|
|
|
218
|
-
override fun pdfToImage(
|
|
271
|
+
override fun pdfToImage(params: ReadableMap, promise: Promise) {
|
|
272
|
+
val pdfPath = params.getString("pdfPath")
|
|
273
|
+
if (pdfPath == null) {
|
|
274
|
+
promise.reject("ERROR", "pdfPath is required")
|
|
275
|
+
return
|
|
276
|
+
}
|
|
219
277
|
withService { service ->
|
|
220
278
|
executor.execute {
|
|
221
279
|
try {
|
|
222
|
-
val
|
|
223
|
-
|
|
280
|
+
val imageType = if (params.getString("imageType") == "JPEG") {
|
|
281
|
+
PrinterImageType.JPEG
|
|
282
|
+
} else {
|
|
283
|
+
PrinterImageType.PNG
|
|
284
|
+
}
|
|
285
|
+
val path = service.printer.pdfToImage(
|
|
286
|
+
PdfToImageParams(
|
|
287
|
+
pdfPath = pdfPath,
|
|
288
|
+
imageType = imageType,
|
|
289
|
+
page = params.optInt("page", 0),
|
|
290
|
+
targetWidthPx = params.optIntOrNull("targetWidthPx")
|
|
291
|
+
)
|
|
292
|
+
)
|
|
224
293
|
promise.resolve(path)
|
|
225
294
|
} catch (e: Exception) {
|
|
226
295
|
promise.reject("ERROR", e.message)
|
|
@@ -229,11 +298,23 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
229
298
|
}
|
|
230
299
|
}
|
|
231
300
|
|
|
232
|
-
override fun printPdf(
|
|
301
|
+
override fun printPdf(params: ReadableMap, promise: Promise) {
|
|
302
|
+
val pdfPath = params.getString("pdfPath")
|
|
303
|
+
if (pdfPath == null) {
|
|
304
|
+
promise.reject("ERROR", "pdfPath is required")
|
|
305
|
+
return
|
|
306
|
+
}
|
|
233
307
|
withService { service ->
|
|
234
308
|
executor.execute {
|
|
235
309
|
try {
|
|
236
|
-
service.printer.printPdf(
|
|
310
|
+
service.printer.printPdf(
|
|
311
|
+
PrintPdfParams(
|
|
312
|
+
pdfPath = pdfPath,
|
|
313
|
+
printerWidthDots = params.optInt("printerWidthDots", 384),
|
|
314
|
+
page = params.optInt("page", 0),
|
|
315
|
+
feedLines = params.optInt("feedLines", 3)
|
|
316
|
+
)
|
|
317
|
+
)
|
|
237
318
|
promise.resolve(null)
|
|
238
319
|
} catch (e: Exception) {
|
|
239
320
|
promise.reject("ERROR", e.message)
|
|
@@ -242,34 +323,41 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
|
|
|
242
323
|
}
|
|
243
324
|
}
|
|
244
325
|
|
|
245
|
-
override fun htmlToPdf(
|
|
326
|
+
override fun htmlToPdf(params: ReadableMap, promise: Promise) {
|
|
327
|
+
val html = params.getString("html")
|
|
328
|
+
if (html == null) {
|
|
329
|
+
promise.reject("ERROR", "html is required")
|
|
330
|
+
return
|
|
331
|
+
}
|
|
246
332
|
withService { service ->
|
|
247
333
|
service.printer.htmlToPdf(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
334
|
+
HtmlToPdfParams(
|
|
335
|
+
html = html,
|
|
336
|
+
pageWidthDp = params.optInt("pageWidthDp", 412),
|
|
337
|
+
heightDp = params.optIntOrNull("heightDp"),
|
|
338
|
+
minPageHeightDp = params.optInt("minPageHeightDp", 1000)
|
|
339
|
+
)
|
|
252
340
|
) { path ->
|
|
253
341
|
promise.resolve(path)
|
|
254
342
|
}
|
|
255
343
|
}
|
|
256
344
|
}
|
|
257
345
|
|
|
258
|
-
override fun printHtml(
|
|
259
|
-
html
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
promise: Promise
|
|
265
|
-
) {
|
|
346
|
+
override fun printHtml(params: ReadableMap, promise: Promise) {
|
|
347
|
+
val html = params.getString("html")
|
|
348
|
+
if (html == null) {
|
|
349
|
+
promise.reject("ERROR", "html is required")
|
|
350
|
+
return
|
|
351
|
+
}
|
|
266
352
|
withService { service ->
|
|
267
353
|
service.printer.printHtml(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
354
|
+
PrintHtmlParams(
|
|
355
|
+
html = html,
|
|
356
|
+
printerWidthDots = params.optInt("printerWidthDots", 384),
|
|
357
|
+
pageWidthDp = params.optInt("pageWidthDp", 412),
|
|
358
|
+
heightDp = params.optIntOrNull("heightDp"),
|
|
359
|
+
minPageHeightDp = params.optInt("minPageHeightDp", 1000)
|
|
360
|
+
)
|
|
273
361
|
) { ok ->
|
|
274
362
|
promise.resolve(ok)
|
|
275
363
|
}
|
|
@@ -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;AAqJ9E,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,48 @@ 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
|
+
};
|
|
19
|
+
export type PrintImageBase64Params = {
|
|
20
|
+
base64: string;
|
|
21
|
+
printerWidthDots?: number;
|
|
22
|
+
feedLines?: number;
|
|
23
|
+
};
|
|
24
|
+
export type PdfToImageParams = {
|
|
25
|
+
pdfPath: string;
|
|
26
|
+
imageType?: PrinterImageType;
|
|
27
|
+
page?: number;
|
|
28
|
+
targetWidthPx?: number;
|
|
29
|
+
};
|
|
30
|
+
export type PrintPdfParams = {
|
|
31
|
+
pdfPath: string;
|
|
32
|
+
printerWidthDots?: number;
|
|
33
|
+
page?: number;
|
|
34
|
+
feedLines?: number;
|
|
35
|
+
};
|
|
36
|
+
export type HtmlToPdfParams = {
|
|
37
|
+
html: string;
|
|
38
|
+
pageWidthDp?: number;
|
|
39
|
+
heightDp?: number;
|
|
40
|
+
minPageHeightDp?: number;
|
|
41
|
+
};
|
|
42
|
+
export type PrintHtmlParams = {
|
|
43
|
+
html: string;
|
|
44
|
+
printerWidthDots?: number;
|
|
45
|
+
pageWidthDp?: number;
|
|
46
|
+
heightDp?: number;
|
|
47
|
+
minPageHeightDp?: number;
|
|
48
|
+
};
|
|
7
49
|
export interface Spec extends TurboModule {
|
|
8
50
|
/**
|
|
9
51
|
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
@@ -25,7 +67,7 @@ export interface Spec extends TurboModule {
|
|
|
25
67
|
* app reconnects automatically next time it's opened (see the README's
|
|
26
68
|
* "Persistent connection" section).
|
|
27
69
|
*/
|
|
28
|
-
connectPrinter(
|
|
70
|
+
connectPrinter(params: ConnectPrinterParams): Promise<boolean>;
|
|
29
71
|
/**
|
|
30
72
|
* Closes the current printer connection, if any, and forgets it for auto-reconnect.
|
|
31
73
|
*/
|
|
@@ -42,43 +84,43 @@ export interface Spec extends TurboModule {
|
|
|
42
84
|
* Print raw text using the printer's built-in font. ASCII only - not
|
|
43
85
|
* suitable for Bangla or other non-Latin scripts, use printHtml() instead.
|
|
44
86
|
*/
|
|
45
|
-
printText(
|
|
87
|
+
printText(params: PrintTextParams): Promise<void>;
|
|
46
88
|
/**
|
|
47
89
|
* Print an image file as a dithered ESC/POS raster image.
|
|
48
|
-
*
|
|
90
|
+
* `printerWidthDots`: 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
49
91
|
*/
|
|
50
|
-
printImage(
|
|
92
|
+
printImage(params: PrintImageParams): Promise<void>;
|
|
51
93
|
/**
|
|
52
94
|
* Print a base64-encoded image as a dithered ESC/POS raster image.
|
|
53
95
|
*/
|
|
54
|
-
printImageBase64(
|
|
96
|
+
printImageBase64(params: PrintImageBase64Params): Promise<void>;
|
|
55
97
|
/**
|
|
56
98
|
* Renders a page of a PDF file to an image file (via Android's PdfRenderer)
|
|
57
99
|
* and returns the image's absolute path.
|
|
58
100
|
*/
|
|
59
|
-
pdfToImage(
|
|
101
|
+
pdfToImage(params: PdfToImageParams): Promise<string>;
|
|
60
102
|
/**
|
|
61
103
|
* Renders a page of a PDF to an image, then prints it.
|
|
62
104
|
*/
|
|
63
|
-
printPdf(
|
|
105
|
+
printPdf(params: PrintPdfParams): Promise<void>;
|
|
64
106
|
/**
|
|
65
107
|
* Renders HTML to a PDF file using an off-screen WebView (no external
|
|
66
108
|
* library) and returns the PDF's absolute path, or null on failure.
|
|
67
109
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
110
|
+
* `pageWidthDp` is the layout width the HTML is rendered at - controls how
|
|
111
|
+
* large the content looks relative to the page, independent of the final
|
|
112
|
+
* printed width (`printerWidthDots` on printHtml/printPdf downscales it).
|
|
113
|
+
* `heightDp`, if set, forces the page to exactly this height (dp) instead
|
|
114
|
+
* of auto-measuring the HTML's real content height. `minPageHeightDp` is
|
|
115
|
+
* ignored if `heightDp` is set - a height floor (dp) for auto-measured
|
|
116
|
+
* content, only relevant for very short/empty HTML.
|
|
75
117
|
*/
|
|
76
|
-
htmlToPdf(
|
|
118
|
+
htmlToPdf(params: HtmlToPdfParams): Promise<string | null>;
|
|
77
119
|
/**
|
|
78
120
|
* Full pipeline: htmlToPdf -> printPdf, in one call. This is how to print
|
|
79
121
|
* content with Bangla or other non-Latin text, or any real HTML/CSS layout.
|
|
80
122
|
*/
|
|
81
|
-
printHtml(
|
|
123
|
+
printHtml(params: PrintHtmlParams): Promise<boolean>;
|
|
82
124
|
}
|
|
83
125
|
declare const _default: Spec;
|
|
84
126
|
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.2.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,56 @@ 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
|
+
};
|
|
24
|
+
|
|
25
|
+
export type PrintImageBase64Params = {
|
|
26
|
+
base64: string;
|
|
27
|
+
printerWidthDots?: number;
|
|
28
|
+
feedLines?: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type PdfToImageParams = {
|
|
32
|
+
pdfPath: string;
|
|
33
|
+
imageType?: PrinterImageType;
|
|
34
|
+
page?: number;
|
|
35
|
+
targetWidthPx?: number;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type PrintPdfParams = {
|
|
39
|
+
pdfPath: string;
|
|
40
|
+
printerWidthDots?: number;
|
|
41
|
+
page?: number;
|
|
42
|
+
feedLines?: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type HtmlToPdfParams = {
|
|
46
|
+
html: string;
|
|
47
|
+
pageWidthDp?: number;
|
|
48
|
+
heightDp?: number;
|
|
49
|
+
minPageHeightDp?: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type PrintHtmlParams = {
|
|
53
|
+
html: string;
|
|
54
|
+
printerWidthDots?: number;
|
|
55
|
+
pageWidthDp?: number;
|
|
56
|
+
heightDp?: number;
|
|
57
|
+
minPageHeightDp?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
10
60
|
export interface Spec extends TurboModule {
|
|
11
61
|
/**
|
|
12
62
|
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
@@ -31,7 +81,7 @@ export interface Spec extends TurboModule {
|
|
|
31
81
|
* app reconnects automatically next time it's opened (see the README's
|
|
32
82
|
* "Persistent connection" section).
|
|
33
83
|
*/
|
|
34
|
-
connectPrinter(
|
|
84
|
+
connectPrinter(params: ConnectPrinterParams): Promise<boolean>;
|
|
35
85
|
|
|
36
86
|
/**
|
|
37
87
|
* Closes the current printer connection, if any, and forgets it for auto-reconnect.
|
|
@@ -52,78 +102,49 @@ export interface Spec extends TurboModule {
|
|
|
52
102
|
* Print raw text using the printer's built-in font. ASCII only - not
|
|
53
103
|
* suitable for Bangla or other non-Latin scripts, use printHtml() instead.
|
|
54
104
|
*/
|
|
55
|
-
printText(
|
|
105
|
+
printText(params: PrintTextParams): Promise<void>;
|
|
56
106
|
|
|
57
107
|
/**
|
|
58
108
|
* Print an image file as a dithered ESC/POS raster image.
|
|
59
|
-
*
|
|
109
|
+
* `printerWidthDots`: 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
60
110
|
*/
|
|
61
|
-
printImage(
|
|
62
|
-
imagePath: string,
|
|
63
|
-
printerWidthDots?: number,
|
|
64
|
-
feedLines?: number
|
|
65
|
-
): Promise<void>;
|
|
111
|
+
printImage(params: PrintImageParams): Promise<void>;
|
|
66
112
|
|
|
67
113
|
/**
|
|
68
114
|
* Print a base64-encoded image as a dithered ESC/POS raster image.
|
|
69
115
|
*/
|
|
70
|
-
printImageBase64(
|
|
71
|
-
base64: string,
|
|
72
|
-
printerWidthDots?: number,
|
|
73
|
-
feedLines?: number
|
|
74
|
-
): Promise<void>;
|
|
116
|
+
printImageBase64(params: PrintImageBase64Params): Promise<void>;
|
|
75
117
|
|
|
76
118
|
/**
|
|
77
119
|
* Renders a page of a PDF file to an image file (via Android's PdfRenderer)
|
|
78
120
|
* and returns the image's absolute path.
|
|
79
121
|
*/
|
|
80
|
-
pdfToImage(
|
|
81
|
-
pdfPath: string,
|
|
82
|
-
imageType?: PrinterImageType,
|
|
83
|
-
page?: number,
|
|
84
|
-
targetWidthPx?: number
|
|
85
|
-
): Promise<string>;
|
|
122
|
+
pdfToImage(params: PdfToImageParams): Promise<string>;
|
|
86
123
|
|
|
87
124
|
/**
|
|
88
125
|
* Renders a page of a PDF to an image, then prints it.
|
|
89
126
|
*/
|
|
90
|
-
printPdf(
|
|
91
|
-
pdfPath: string,
|
|
92
|
-
printerWidthDots?: number,
|
|
93
|
-
page?: number,
|
|
94
|
-
feedLines?: number
|
|
95
|
-
): Promise<void>;
|
|
127
|
+
printPdf(params: PrintPdfParams): Promise<void>;
|
|
96
128
|
|
|
97
129
|
/**
|
|
98
130
|
* Renders HTML to a PDF file using an off-screen WebView (no external
|
|
99
131
|
* library) and returns the PDF's absolute path, or null on failure.
|
|
100
132
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
133
|
+
* `pageWidthDp` is the layout width the HTML is rendered at - controls how
|
|
134
|
+
* large the content looks relative to the page, independent of the final
|
|
135
|
+
* printed width (`printerWidthDots` on printHtml/printPdf downscales it).
|
|
136
|
+
* `heightDp`, if set, forces the page to exactly this height (dp) instead
|
|
137
|
+
* of auto-measuring the HTML's real content height. `minPageHeightDp` is
|
|
138
|
+
* ignored if `heightDp` is set - a height floor (dp) for auto-measured
|
|
139
|
+
* content, only relevant for very short/empty HTML.
|
|
108
140
|
*/
|
|
109
|
-
htmlToPdf(
|
|
110
|
-
html: string,
|
|
111
|
-
pageWidthDp?: number,
|
|
112
|
-
heightDp?: number,
|
|
113
|
-
minPageHeightDp?: number
|
|
114
|
-
): Promise<string | null>;
|
|
141
|
+
htmlToPdf(params: HtmlToPdfParams): Promise<string | null>;
|
|
115
142
|
|
|
116
143
|
/**
|
|
117
144
|
* Full pipeline: htmlToPdf -> printPdf, in one call. This is how to print
|
|
118
145
|
* content with Bangla or other non-Latin text, or any real HTML/CSS layout.
|
|
119
146
|
*/
|
|
120
|
-
printHtml(
|
|
121
|
-
html: string,
|
|
122
|
-
printerWidthDots?: number,
|
|
123
|
-
pageWidthDp?: number,
|
|
124
|
-
heightDp?: number,
|
|
125
|
-
minPageHeightDp?: number
|
|
126
|
-
): Promise<boolean>;
|
|
147
|
+
printHtml(params: PrintHtmlParams): Promise<boolean>;
|
|
127
148
|
}
|
|
128
149
|
|
|
129
150
|
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;
|