@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
package/src/index.tsx
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import ReactNativePrinterKit, {
|
|
2
|
+
type BluetoothPrinterDevice,
|
|
3
|
+
type PrinterImageType,
|
|
4
|
+
} from './NativeReactNativePrinterKit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether Bluetooth permission is already granted (always true below Android 12).
|
|
8
|
+
*/
|
|
9
|
+
export function hasBluetoothPermission(): boolean {
|
|
10
|
+
return ReactNativePrinterKit.hasBluetoothPermission();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Shows the system permission dialog if needed, and resolves with the result.
|
|
15
|
+
*/
|
|
16
|
+
export function requestBluetoothPermission(): Promise<boolean> {
|
|
17
|
+
return ReactNativePrinterKit.requestBluetoothPermission();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get all Bluetooth devices already paired (bonded) with this device.
|
|
22
|
+
*/
|
|
23
|
+
export function getBondedBluetoothPrinters(): BluetoothPrinterDevice[] {
|
|
24
|
+
return ReactNativePrinterKit.getBondedBluetoothPrinters();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Connect to a paired Bluetooth printer by its MAC address. The connection
|
|
29
|
+
* survives the app being swiped from Recents, and is reconnected to
|
|
30
|
+
* automatically the next time the app starts.
|
|
31
|
+
*/
|
|
32
|
+
export function connectPrinter(address: string): Promise<boolean> {
|
|
33
|
+
return ReactNativePrinterKit.connectPrinter(address);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Disconnect from the current printer.
|
|
38
|
+
*/
|
|
39
|
+
export function disconnectPrinter(): Promise<void> {
|
|
40
|
+
return ReactNativePrinterKit.disconnectPrinter();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check if a printer is currently connected.
|
|
45
|
+
*/
|
|
46
|
+
export function isConnectedPrinter(): Promise<boolean> {
|
|
47
|
+
return ReactNativePrinterKit.isConnectedPrinter();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the currently connected printer, if any.
|
|
52
|
+
*/
|
|
53
|
+
export function getConnectedPrinter(): Promise<BluetoothPrinterDevice | null> {
|
|
54
|
+
return ReactNativePrinterKit.getConnectedPrinter();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Print raw text using the printer's built-in font (ASCII only - use
|
|
59
|
+
* printHtml() for Bangla or other non-Latin scripts).
|
|
60
|
+
*/
|
|
61
|
+
export function printText(text: string, feedLines?: number): Promise<void> {
|
|
62
|
+
return ReactNativePrinterKit.printText(text, feedLines);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Print an image file as an ESC/POS raster image.
|
|
67
|
+
* @param printerWidthDots 384 for 58mm printers, 576 for 80mm printers (default 384).
|
|
68
|
+
*/
|
|
69
|
+
export function printImage(
|
|
70
|
+
imagePath: string,
|
|
71
|
+
printerWidthDots?: number,
|
|
72
|
+
feedLines?: number
|
|
73
|
+
): Promise<void> {
|
|
74
|
+
return ReactNativePrinterKit.printImage(imagePath, printerWidthDots, feedLines);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Print a base64-encoded image as an ESC/POS raster image.
|
|
79
|
+
*/
|
|
80
|
+
export function printImageBase64(
|
|
81
|
+
base64: string,
|
|
82
|
+
printerWidthDots?: number,
|
|
83
|
+
feedLines?: number
|
|
84
|
+
): Promise<void> {
|
|
85
|
+
return ReactNativePrinterKit.printImageBase64(base64, printerWidthDots, feedLines);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Render a page of a PDF file to an image file. Returns the image path.
|
|
90
|
+
*/
|
|
91
|
+
export function pdfToImage(
|
|
92
|
+
pdfPath: string,
|
|
93
|
+
imageType?: PrinterImageType,
|
|
94
|
+
page?: number,
|
|
95
|
+
targetWidthPx?: number
|
|
96
|
+
): Promise<string> {
|
|
97
|
+
return ReactNativePrinterKit.pdfToImage(pdfPath, imageType, page, targetWidthPx);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Render a page of a PDF to an image, then print it.
|
|
102
|
+
*/
|
|
103
|
+
export function printPdf(
|
|
104
|
+
pdfPath: string,
|
|
105
|
+
printerWidthDots?: number,
|
|
106
|
+
page?: number,
|
|
107
|
+
feedLines?: number
|
|
108
|
+
): Promise<void> {
|
|
109
|
+
return ReactNativePrinterKit.printPdf(pdfPath, printerWidthDots, page, feedLines);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Render HTML to a PDF file and return its path, or null on failure. See
|
|
114
|
+
* NativeReactNativePrinterKit's Spec for what pageWidthDp/heightDp/minPageHeightDp control.
|
|
115
|
+
*/
|
|
116
|
+
export function htmlToPdf(
|
|
117
|
+
html: string,
|
|
118
|
+
pageWidthDp?: number,
|
|
119
|
+
heightDp?: number,
|
|
120
|
+
minPageHeightDp?: number
|
|
121
|
+
): Promise<string | null> {
|
|
122
|
+
return ReactNativePrinterKit.htmlToPdf(html, pageWidthDp, heightDp, minPageHeightDp);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Full pipeline: render HTML to PDF, then print it - the way to print Bangla
|
|
127
|
+
* (or other non-Latin) text or any real HTML/CSS layout.
|
|
128
|
+
*/
|
|
129
|
+
export function printHtml(
|
|
130
|
+
html: string,
|
|
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
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Export types
|
|
146
|
+
export type { BluetoothPrinterDevice, PrinterImageType };
|
|
147
|
+
|
|
148
|
+
// Export native module
|
|
149
|
+
export default ReactNativePrinterKit;
|