@rejaul/react-native-printer-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +199 -0
- package/ReactNativePrinterKit.podspec +20 -0
- package/android/build.gradle +65 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/rejaul/reactnativeprinterkit/ReactNativePrinterKitModule.kt +283 -0
- package/android/src/main/java/com/rejaul/reactnativeprinterkit/ReactNativePrinterKitPackage.kt +31 -0
- package/ios/ReactNativePrinterKit.h +5 -0
- package/ios/ReactNativePrinterKit.mm +21 -0
- package/lib/module/NativeReactNativePrinterKit.js +8 -0
- package/lib/module/NativeReactNativePrinterKit.js.map +1 -0
- package/lib/module/index.js +113 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeReactNativePrinterKit.d.ts +85 -0
- package/lib/typescript/src/NativeReactNativePrinterKit.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +66 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +133 -0
- package/src/NativeReactNativePrinterKit.ts +135 -0
- package/src/index.tsx +149 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import ReactNativePrinterKit from "./NativeReactNativePrinterKit.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
7
|
+
*/
|
|
8
|
+
export function hasBluetoothPermission() {
|
|
9
|
+
return ReactNativePrinterKit.hasBluetoothPermission();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Shows the system permission dialog if needed, and resolves with the result.
|
|
14
|
+
*/
|
|
15
|
+
export function requestBluetoothPermission() {
|
|
16
|
+
return ReactNativePrinterKit.requestBluetoothPermission();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get all Bluetooth devices already paired (bonded) with this device.
|
|
21
|
+
*/
|
|
22
|
+
export function getBondedBluetoothPrinters() {
|
|
23
|
+
return ReactNativePrinterKit.getBondedBluetoothPrinters();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Connect to a paired Bluetooth printer by its MAC address. The connection
|
|
28
|
+
* survives the app being swiped from Recents, and is reconnected to
|
|
29
|
+
* automatically the next time the app starts.
|
|
30
|
+
*/
|
|
31
|
+
export function connectPrinter(address) {
|
|
32
|
+
return ReactNativePrinterKit.connectPrinter(address);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Disconnect from the current printer.
|
|
37
|
+
*/
|
|
38
|
+
export function disconnectPrinter() {
|
|
39
|
+
return ReactNativePrinterKit.disconnectPrinter();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Check if a printer is currently connected.
|
|
44
|
+
*/
|
|
45
|
+
export function isConnectedPrinter() {
|
|
46
|
+
return ReactNativePrinterKit.isConnectedPrinter();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get the currently connected printer, if any.
|
|
51
|
+
*/
|
|
52
|
+
export function getConnectedPrinter() {
|
|
53
|
+
return ReactNativePrinterKit.getConnectedPrinter();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Print raw text using the printer's built-in font (ASCII only - use
|
|
58
|
+
* printHtml() for Bangla or other non-Latin scripts).
|
|
59
|
+
*/
|
|
60
|
+
export function printText(text, feedLines) {
|
|
61
|
+
return ReactNativePrinterKit.printText(text, feedLines);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Print an image file as an ESC/POS raster image.
|
|
66
|
+
* @param printerWidthDots 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
67
|
+
*/
|
|
68
|
+
export function printImage(imagePath, printerWidthDots, feedLines) {
|
|
69
|
+
return ReactNativePrinterKit.printImage(imagePath, printerWidthDots, feedLines);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Print a base64-encoded image as an ESC/POS raster image.
|
|
74
|
+
*/
|
|
75
|
+
export function printImageBase64(base64, printerWidthDots, feedLines) {
|
|
76
|
+
return ReactNativePrinterKit.printImageBase64(base64, printerWidthDots, feedLines);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Render a page of a PDF file to an image file. Returns the image path.
|
|
81
|
+
*/
|
|
82
|
+
export function pdfToImage(pdfPath, imageType, page, targetWidthPx) {
|
|
83
|
+
return ReactNativePrinterKit.pdfToImage(pdfPath, imageType, page, targetWidthPx);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Render a page of a PDF to an image, then print it.
|
|
88
|
+
*/
|
|
89
|
+
export function printPdf(pdfPath, printerWidthDots, page, feedLines) {
|
|
90
|
+
return ReactNativePrinterKit.printPdf(pdfPath, printerWidthDots, page, feedLines);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Render HTML to a PDF file and return its path, or null on failure. See
|
|
95
|
+
* NativeReactNativePrinterKit's Spec for what pageWidthDp/heightDp/minPageHeightDp control.
|
|
96
|
+
*/
|
|
97
|
+
export function htmlToPdf(html, pageWidthDp, heightDp, minPageHeightDp) {
|
|
98
|
+
return ReactNativePrinterKit.htmlToPdf(html, pageWidthDp, heightDp, minPageHeightDp);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Full pipeline: render HTML to PDF, then print it - the way to print Bangla
|
|
103
|
+
* (or other non-Latin) text or any real HTML/CSS layout.
|
|
104
|
+
*/
|
|
105
|
+
export function printHtml(html, printerWidthDots, pageWidthDp, heightDp, minPageHeightDp) {
|
|
106
|
+
return ReactNativePrinterKit.printHtml(html, printerWidthDots, pageWidthDp, heightDp, minPageHeightDp);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Export types
|
|
110
|
+
|
|
111
|
+
// Export native module
|
|
112
|
+
export default ReactNativePrinterKit;
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ReactNativePrinterKit","hasBluetoothPermission","requestBluetoothPermission","getBondedBluetoothPrinters","connectPrinter","address","disconnectPrinter","isConnectedPrinter","getConnectedPrinter","printText","text","feedLines","printImage","imagePath","printerWidthDots","printImageBase64","base64","pdfToImage","pdfPath","imageType","page","targetWidthPx","printPdf","htmlToPdf","html","pageWidthDp","heightDp","minPageHeightDp","printHtml"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,qBAAqB,MAGrB,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,OAAe,EAAoB;EAChE,OAAOL,qBAAqB,CAACI,cAAc,CAACC,OAAO,CAAC;AACtD;;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;AAC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A;AACA,OAAO,SAASC,SAASA,CACvBJ,IAAY,EACZV,gBAAyB,EACzBW,WAAoB,EACpBC,QAAiB,EACjBC,eAAwB,EACN;EAClB,OAAO3B,qBAAqB,CAAC4B,SAAS,CACpCJ,IAAI,EACJV,gBAAgB,EAChBW,WAAW,EACXC,QAAQ,EACRC,eACF,CAAC;AACH;;AAEA;;AAGA;AACA,eAAe3B,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { type TurboModule } from 'react-native';
|
|
2
|
+
export type BluetoothPrinterDevice = {
|
|
3
|
+
name: string | null;
|
|
4
|
+
address: string;
|
|
5
|
+
};
|
|
6
|
+
export type PrinterImageType = 'PNG' | 'JPEG';
|
|
7
|
+
export interface Spec extends TurboModule {
|
|
8
|
+
/**
|
|
9
|
+
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
10
|
+
*/
|
|
11
|
+
hasBluetoothPermission(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Shows the system permission dialog if needed, and resolves with the result.
|
|
14
|
+
* A no-op that resolves `true` on Android < 12, where no runtime grant is needed.
|
|
15
|
+
*/
|
|
16
|
+
requestBluetoothPermission(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns all Bluetooth devices already paired (bonded) with this device.
|
|
19
|
+
* On Android 12+ this requires the BLUETOOTH_CONNECT permission to be granted.
|
|
20
|
+
*/
|
|
21
|
+
getBondedBluetoothPrinters(): BluetoothPrinterDevice[];
|
|
22
|
+
/**
|
|
23
|
+
* Opens a Bluetooth SPP connection to the paired printer at the given address.
|
|
24
|
+
* Closes any existing printer connection first. Remembers the address so the
|
|
25
|
+
* app reconnects automatically next time it's opened (see the README's
|
|
26
|
+
* "Persistent connection" section).
|
|
27
|
+
*/
|
|
28
|
+
connectPrinter(address: string): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Closes the current printer connection, if any, and forgets it for auto-reconnect.
|
|
31
|
+
*/
|
|
32
|
+
disconnectPrinter(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a printer connection is currently open.
|
|
35
|
+
*/
|
|
36
|
+
isConnectedPrinter(): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Get the currently connected printer, if any.
|
|
39
|
+
*/
|
|
40
|
+
getConnectedPrinter(): Promise<BluetoothPrinterDevice | null>;
|
|
41
|
+
/**
|
|
42
|
+
* Print raw text using the printer's built-in font. ASCII only - not
|
|
43
|
+
* suitable for Bangla or other non-Latin scripts, use printHtml() instead.
|
|
44
|
+
*/
|
|
45
|
+
printText(text: string, feedLines?: number): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Print an image file as a dithered ESC/POS raster image.
|
|
48
|
+
* @param printerWidthDots 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
49
|
+
*/
|
|
50
|
+
printImage(imagePath: string, printerWidthDots?: number, feedLines?: number): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Print a base64-encoded image as a dithered ESC/POS raster image.
|
|
53
|
+
*/
|
|
54
|
+
printImageBase64(base64: string, printerWidthDots?: number, feedLines?: number): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Renders a page of a PDF file to an image file (via Android's PdfRenderer)
|
|
57
|
+
* and returns the image's absolute path.
|
|
58
|
+
*/
|
|
59
|
+
pdfToImage(pdfPath: string, imageType?: PrinterImageType, page?: number, targetWidthPx?: number): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Renders a page of a PDF to an image, then prints it.
|
|
62
|
+
*/
|
|
63
|
+
printPdf(pdfPath: string, printerWidthDots?: number, page?: number, feedLines?: number): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Renders HTML to a PDF file using an off-screen WebView (no external
|
|
66
|
+
* library) and returns the PDF's absolute path, or null on failure.
|
|
67
|
+
*
|
|
68
|
+
* @param pageWidthDp layout width in dp the HTML is rendered at - controls
|
|
69
|
+
* how large the content looks relative to the page, independent of the
|
|
70
|
+
* final printed width (printerWidthDots on printHtml/printPdf downscales it).
|
|
71
|
+
* @param heightDp if set, forces the page to exactly this height (dp) instead
|
|
72
|
+
* of auto-measuring the HTML's real content height.
|
|
73
|
+
* @param minPageHeightDp ignored if heightDp is set - a height floor (dp) for
|
|
74
|
+
* auto-measured content, only relevant for very short/empty HTML.
|
|
75
|
+
*/
|
|
76
|
+
htmlToPdf(html: string, pageWidthDp?: number, heightDp?: number, minPageHeightDp?: number): Promise<string | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Full pipeline: htmlToPdf -> printPdf, in one call. This is how to print
|
|
79
|
+
* content with Bangla or other non-Latin text, or any real HTML/CSS layout.
|
|
80
|
+
*/
|
|
81
|
+
printHtml(html: string, printerWidthDots?: number, pageWidthDp?: number, heightDp?: number, minPageHeightDp?: number): Promise<boolean>;
|
|
82
|
+
}
|
|
83
|
+
declare const _default: Spec;
|
|
84
|
+
export default _default;
|
|
85
|
+
//# sourceMappingURL=NativeReactNativePrinterKit.d.ts.map
|
|
@@ -0,0 +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,WAAW,IAAK,SAAQ,WAAW;IACvC;;OAEG;IACH,sBAAsB,IAAI,OAAO,CAAC;IAElC;;;OAGG;IACH,0BAA0B,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE/C;;;OAGG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CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE1B;;;OAGG;IACH,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,gBAAgB,CAAC,EAAE,MAAM,EACzB,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;;AAQD,wBAA2B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import ReactNativePrinterKit, { type BluetoothPrinterDevice, type PrinterImageType } from './NativeReactNativePrinterKit.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
4
|
+
*/
|
|
5
|
+
export declare function hasBluetoothPermission(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Shows the system permission dialog if needed, and resolves with the result.
|
|
8
|
+
*/
|
|
9
|
+
export declare function requestBluetoothPermission(): Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Get all Bluetooth devices already paired (bonded) with this device.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getBondedBluetoothPrinters(): BluetoothPrinterDevice[];
|
|
14
|
+
/**
|
|
15
|
+
* Connect to a paired Bluetooth printer by its MAC address. The connection
|
|
16
|
+
* survives the app being swiped from Recents, and is reconnected to
|
|
17
|
+
* automatically the next time the app starts.
|
|
18
|
+
*/
|
|
19
|
+
export declare function connectPrinter(address: string): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Disconnect from the current printer.
|
|
22
|
+
*/
|
|
23
|
+
export declare function disconnectPrinter(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a printer is currently connected.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isConnectedPrinter(): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Get the currently connected printer, if any.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getConnectedPrinter(): Promise<BluetoothPrinterDevice | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Print raw text using the printer's built-in font (ASCII only - use
|
|
34
|
+
* printHtml() for Bangla or other non-Latin scripts).
|
|
35
|
+
*/
|
|
36
|
+
export declare function printText(text: string, feedLines?: number): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Print an image file as an ESC/POS raster image.
|
|
39
|
+
* @param printerWidthDots 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
40
|
+
*/
|
|
41
|
+
export declare function printImage(imagePath: string, printerWidthDots?: number, feedLines?: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Print a base64-encoded image as an ESC/POS raster image.
|
|
44
|
+
*/
|
|
45
|
+
export declare function printImageBase64(base64: string, printerWidthDots?: number, feedLines?: number): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Render a page of a PDF file to an image file. Returns the image path.
|
|
48
|
+
*/
|
|
49
|
+
export declare function pdfToImage(pdfPath: string, imageType?: PrinterImageType, page?: number, targetWidthPx?: number): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Render a page of a PDF to an image, then print it.
|
|
52
|
+
*/
|
|
53
|
+
export declare function printPdf(pdfPath: string, printerWidthDots?: number, page?: number, feedLines?: number): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Render HTML to a PDF file and return its path, or null on failure. See
|
|
56
|
+
* NativeReactNativePrinterKit's Spec for what pageWidthDp/heightDp/minPageHeightDp control.
|
|
57
|
+
*/
|
|
58
|
+
export declare function htmlToPdf(html: string, pageWidthDp?: number, heightDp?: number, minPageHeightDp?: number): Promise<string | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Full pipeline: render HTML to PDF, then print it - the way to print Bangla
|
|
61
|
+
* (or other non-Latin) text or any real HTML/CSS layout.
|
|
62
|
+
*/
|
|
63
|
+
export declare function printHtml(html: string, printerWidthDots?: number, pageWidthDp?: number, heightDp?: number, minPageHeightDp?: number): Promise<boolean>;
|
|
64
|
+
export type { BluetoothPrinterDevice, PrinterImageType };
|
|
65
|
+
export default ReactNativePrinterKit;
|
|
66
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,EACtB,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,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEhE;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,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,gBAAgB,CAAC,EAAE,MAAM,EACzB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,gBAAgB,CAAC,EAAE,MAAM,EACzB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,gBAAgB,EAC5B,IAAI,CAAC,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,MAAM,EACzB,IAAI,CAAC,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAExB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,gBAAgB,CAAC,EAAE,MAAM,EACzB,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,OAAO,CAAC,CAQlB;AAGD,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,CAAC;AAGzD,eAAe,qBAAqB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rejaul/react-native-printer-kit",
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"rejaul-react-native-printer-kit-source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace @rejaul/react-native-printer-kit-example",
|
|
36
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\""
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"react-native",
|
|
43
|
+
"android",
|
|
44
|
+
"bluetooth",
|
|
45
|
+
"printer",
|
|
46
|
+
"pos",
|
|
47
|
+
"escpos",
|
|
48
|
+
"thermal-printer",
|
|
49
|
+
"receipt-printer",
|
|
50
|
+
"bangla"
|
|
51
|
+
],
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/DeveloperRejaul/react-native-printer-kit.git"
|
|
55
|
+
},
|
|
56
|
+
"author": "Rejaul Karim <devrejaul.official@gmail.com> (https://github.com/DeveloperRejaul)",
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/DeveloperRejaul/react-native-printer-kit/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://github.com/DeveloperRejaul/react-native-printer-kit#readme",
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"registry": "https://registry.npmjs.org/"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@eslint/compat": "^2.1.0",
|
|
67
|
+
"@eslint/eslintrc": "^3.3.6",
|
|
68
|
+
"@eslint/js": "^9.39.5",
|
|
69
|
+
"@react-native/babel-preset": "0.86.2",
|
|
70
|
+
"@react-native/eslint-config": "0.86.2",
|
|
71
|
+
"@types/react": "^19.2.0",
|
|
72
|
+
"del-cli": "^7.0.0",
|
|
73
|
+
"eslint": "^9.39.5",
|
|
74
|
+
"eslint-config-prettier": "^10.1.8",
|
|
75
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
76
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
77
|
+
"prettier": "^3.9.6",
|
|
78
|
+
"react": "19.2.3",
|
|
79
|
+
"react-native": "0.86.2",
|
|
80
|
+
"react-native-builder-bob": "^0.43.0",
|
|
81
|
+
"turbo": "^2.10.8",
|
|
82
|
+
"typescript": "^6.0.3"
|
|
83
|
+
},
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"react": "*",
|
|
86
|
+
"react-native": "*"
|
|
87
|
+
},
|
|
88
|
+
"workspaces": [
|
|
89
|
+
"example"
|
|
90
|
+
],
|
|
91
|
+
"packageManager": "yarn@4.11.0",
|
|
92
|
+
"react-native-builder-bob": {
|
|
93
|
+
"source": "src",
|
|
94
|
+
"output": "lib",
|
|
95
|
+
"targets": [
|
|
96
|
+
[
|
|
97
|
+
"module",
|
|
98
|
+
{
|
|
99
|
+
"esm": true
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
"typescript",
|
|
104
|
+
{
|
|
105
|
+
"project": "tsconfig.build.json"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"codegenConfig": {
|
|
111
|
+
"name": "ReactNativePrinterKitSpec",
|
|
112
|
+
"type": "modules",
|
|
113
|
+
"jsSrcsDir": "src",
|
|
114
|
+
"android": {
|
|
115
|
+
"javaPackageName": "com.rejaul.reactnativeprinterkit"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"prettier": {
|
|
119
|
+
"quoteProps": "consistent",
|
|
120
|
+
"singleQuote": true,
|
|
121
|
+
"tabWidth": 2,
|
|
122
|
+
"trailingComma": "es5",
|
|
123
|
+
"useTabs": false
|
|
124
|
+
},
|
|
125
|
+
"create-react-native-library": {
|
|
126
|
+
"type": "turbo-module",
|
|
127
|
+
"languages": "kotlin-objc",
|
|
128
|
+
"tools": [
|
|
129
|
+
"eslint"
|
|
130
|
+
],
|
|
131
|
+
"version": "0.63.1"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { TurboModuleRegistry, type TurboModule, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type BluetoothPrinterDevice = {
|
|
4
|
+
name: string | null;
|
|
5
|
+
address: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type PrinterImageType = 'PNG' | 'JPEG';
|
|
9
|
+
|
|
10
|
+
export interface Spec extends TurboModule {
|
|
11
|
+
/**
|
|
12
|
+
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
13
|
+
*/
|
|
14
|
+
hasBluetoothPermission(): boolean;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Shows the system permission dialog if needed, and resolves with the result.
|
|
18
|
+
* A no-op that resolves `true` on Android < 12, where no runtime grant is needed.
|
|
19
|
+
*/
|
|
20
|
+
requestBluetoothPermission(): Promise<boolean>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns all Bluetooth devices already paired (bonded) with this device.
|
|
24
|
+
* On Android 12+ this requires the BLUETOOTH_CONNECT permission to be granted.
|
|
25
|
+
*/
|
|
26
|
+
getBondedBluetoothPrinters(): BluetoothPrinterDevice[];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Opens a Bluetooth SPP connection to the paired printer at the given address.
|
|
30
|
+
* Closes any existing printer connection first. Remembers the address so the
|
|
31
|
+
* app reconnects automatically next time it's opened (see the README's
|
|
32
|
+
* "Persistent connection" section).
|
|
33
|
+
*/
|
|
34
|
+
connectPrinter(address: string): Promise<boolean>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Closes the current printer connection, if any, and forgets it for auto-reconnect.
|
|
38
|
+
*/
|
|
39
|
+
disconnectPrinter(): Promise<void>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if a printer connection is currently open.
|
|
43
|
+
*/
|
|
44
|
+
isConnectedPrinter(): Promise<boolean>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the currently connected printer, if any.
|
|
48
|
+
*/
|
|
49
|
+
getConnectedPrinter(): Promise<BluetoothPrinterDevice | null>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Print raw text using the printer's built-in font. ASCII only - not
|
|
53
|
+
* suitable for Bangla or other non-Latin scripts, use printHtml() instead.
|
|
54
|
+
*/
|
|
55
|
+
printText(text: string, feedLines?: number): Promise<void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Print an image file as a dithered ESC/POS raster image.
|
|
59
|
+
* @param printerWidthDots 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
60
|
+
*/
|
|
61
|
+
printImage(
|
|
62
|
+
imagePath: string,
|
|
63
|
+
printerWidthDots?: number,
|
|
64
|
+
feedLines?: number
|
|
65
|
+
): Promise<void>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Print a base64-encoded image as a dithered ESC/POS raster image.
|
|
69
|
+
*/
|
|
70
|
+
printImageBase64(
|
|
71
|
+
base64: string,
|
|
72
|
+
printerWidthDots?: number,
|
|
73
|
+
feedLines?: number
|
|
74
|
+
): Promise<void>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Renders a page of a PDF file to an image file (via Android's PdfRenderer)
|
|
78
|
+
* and returns the image's absolute path.
|
|
79
|
+
*/
|
|
80
|
+
pdfToImage(
|
|
81
|
+
pdfPath: string,
|
|
82
|
+
imageType?: PrinterImageType,
|
|
83
|
+
page?: number,
|
|
84
|
+
targetWidthPx?: number
|
|
85
|
+
): Promise<string>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Renders a page of a PDF to an image, then prints it.
|
|
89
|
+
*/
|
|
90
|
+
printPdf(
|
|
91
|
+
pdfPath: string,
|
|
92
|
+
printerWidthDots?: number,
|
|
93
|
+
page?: number,
|
|
94
|
+
feedLines?: number
|
|
95
|
+
): Promise<void>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Renders HTML to a PDF file using an off-screen WebView (no external
|
|
99
|
+
* library) and returns the PDF's absolute path, or null on failure.
|
|
100
|
+
*
|
|
101
|
+
* @param pageWidthDp layout width in dp the HTML is rendered at - controls
|
|
102
|
+
* how large the content looks relative to the page, independent of the
|
|
103
|
+
* final printed width (printerWidthDots on printHtml/printPdf downscales it).
|
|
104
|
+
* @param heightDp if set, forces the page to exactly this height (dp) instead
|
|
105
|
+
* of auto-measuring the HTML's real content height.
|
|
106
|
+
* @param minPageHeightDp ignored if heightDp is set - a height floor (dp) for
|
|
107
|
+
* auto-measured content, only relevant for very short/empty HTML.
|
|
108
|
+
*/
|
|
109
|
+
htmlToPdf(
|
|
110
|
+
html: string,
|
|
111
|
+
pageWidthDp?: number,
|
|
112
|
+
heightDp?: number,
|
|
113
|
+
minPageHeightDp?: number
|
|
114
|
+
): Promise<string | null>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Full pipeline: htmlToPdf -> printPdf, in one call. This is how to print
|
|
118
|
+
* content with Bangla or other non-Latin text, or any real HTML/CSS layout.
|
|
119
|
+
*/
|
|
120
|
+
printHtml(
|
|
121
|
+
html: string,
|
|
122
|
+
printerWidthDots?: number,
|
|
123
|
+
pageWidthDp?: number,
|
|
124
|
+
heightDp?: number,
|
|
125
|
+
minPageHeightDp?: number
|
|
126
|
+
): Promise<boolean>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getModule(): Spec {
|
|
130
|
+
return Platform.OS === 'android'
|
|
131
|
+
? TurboModuleRegistry.getEnforcing<Spec>('ReactNativePrinterKit')
|
|
132
|
+
: ({} as Spec);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export default getModule();
|