react-native-earl-thermal-printer 1.0.1 → 1.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.
Files changed (33) hide show
  1. package/README.md +114 -22
  2. package/android/.project +0 -6
  3. package/android/src/main/java/com/pinmi/react/printer/RNBLEPrinterModule.java +4 -4
  4. package/android/src/main/java/com/pinmi/react/printer/RNNetPrinterModule.java +4 -4
  5. package/android/src/main/java/com/pinmi/react/printer/RNPrinterModule.java +2 -2
  6. package/android/src/main/java/com/pinmi/react/printer/RNUSBPrinterModule.java +4 -4
  7. package/android/src/main/java/com/pinmi/react/printer/adapter/BLEPrinterAdapter.java +17 -15
  8. package/android/src/main/java/com/pinmi/react/printer/adapter/NetPrinterAdapter.java +17 -15
  9. package/android/src/main/java/com/pinmi/react/printer/adapter/PrinterAdapter.java +2 -2
  10. package/android/src/main/java/com/pinmi/react/printer/adapter/USBPrinterAdapter.java +17 -15
  11. package/dist/NativeBLEPrinter.d.ts +2 -2
  12. package/dist/NativeBLEPrinter.d.ts.map +1 -1
  13. package/dist/NativeNetPrinter.d.ts +2 -2
  14. package/dist/NativeNetPrinter.d.ts.map +1 -1
  15. package/dist/NativeUSBPrinter.d.ts +2 -2
  16. package/dist/NativeUSBPrinter.d.ts.map +1 -1
  17. package/dist/index.d.ts +6 -6
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +6 -6
  20. package/dist/index.js.map +1 -1
  21. package/dist/utils/EPToolkit.d.ts +4 -1
  22. package/dist/utils/EPToolkit.d.ts.map +1 -1
  23. package/dist/utils/EPToolkit.js +212 -20
  24. package/dist/utils/EPToolkit.js.map +1 -1
  25. package/ios/RNBLEPrinter.mm +4 -1
  26. package/ios/RNNetPrinter.mm +4 -1
  27. package/ios/RNUSBPrinter.mm +2 -0
  28. package/package.json +1 -1
  29. package/src/NativeBLEPrinter.ts +2 -2
  30. package/src/NativeNetPrinter.ts +2 -2
  31. package/src/NativeUSBPrinter.ts +2 -2
  32. package/src/index.ts +12 -12
  33. package/src/utils/EPToolkit.ts +270 -20
package/README.md CHANGED
@@ -73,6 +73,8 @@ const devices = await USBPrinter.getDeviceList();
73
73
  await USBPrinter.connectPrinter(devices[0].vendor_id, devices[0].product_id);
74
74
  await USBPrinter.printText("Hello from USB!\n");
75
75
  await USBPrinter.printBill("Receipt line\n");
76
+ await USBPrinter.printImage("https://example.com/logo.png", 300);
77
+ await USBPrinter.printQrCode("https://example.com", 200);
76
78
  USBPrinter.closeConn();
77
79
  ```
78
80
 
@@ -84,6 +86,8 @@ const devices = await BLEPrinter.getDeviceList();
84
86
  await BLEPrinter.connectPrinter(devices[0].inner_mac_address);
85
87
  await BLEPrinter.printText("Hello from BLE!\n");
86
88
  await BLEPrinter.printBill("Receipt line\n");
89
+ await BLEPrinter.printImage("https://example.com/logo.png", 300);
90
+ await BLEPrinter.printQrCode("https://example.com", 200);
87
91
  BLEPrinter.closeConn();
88
92
  ```
89
93
 
@@ -102,6 +106,8 @@ const devices = await NetPrinter.getDeviceList();
102
106
  await NetPrinter.connectPrinter("192.168.1.100", 9100);
103
107
  await NetPrinter.printText("Hello from Network!\n");
104
108
  await NetPrinter.printBill("Receipt line\n");
109
+ await NetPrinter.printImage("https://example.com/logo.png", 300);
110
+ await NetPrinter.printQrCode("https://example.com", 200);
105
111
  NetPrinter.closeConn();
106
112
  ```
107
113
 
@@ -137,13 +143,13 @@ Print a text string using ESC/POS encoding. Supports formatting tags (see below)
137
143
 
138
144
  Same as `printText` but defaults `beep`, `cut`, and `tailingLine` to `true`.
139
145
 
140
- ### `printImage(imageUrl: string): Promise<void>`
146
+ ### `printImage(imageUrl: string, imageWidth?: number): Promise<void>`
141
147
 
142
- Print an image from a URL.
148
+ Print an image from a URL. The optional `imageWidth` parameter controls the maximum width in pixels for the printed image (default: `200` on Android, `150` on iOS).
143
149
 
144
- ### `printQrCode(qrCode: string): Promise<void>`
150
+ ### `printQrCode(qrCode: string, qrSize?: number): Promise<void>`
145
151
 
146
- Print a QR code.
152
+ Print a QR code. The optional `qrSize` parameter controls the size in pixels of the generated QR code (default: `250`).
147
153
 
148
154
  ### `closeConn(): void`
149
155
 
@@ -166,26 +172,111 @@ interface PrinterOptions {
166
172
 
167
173
  ## ESC/POS Formatting Tags
168
174
 
169
- The text helpers (`printText`, `printBill`) support inline formatting tags:
175
+ The text helpers (`printText`, `printBill`) support inline formatting tags.
176
+ All formatting **resets automatically on every `\n`** (newline), so tags apply per-line.
170
177
 
171
- | Tag | Description |
172
- | -------------- | ---------------------- |
173
- | `<B>...</B>` | **Bold** |
174
- | `<C>...</C>` | Center-aligned |
175
- | `<D>...</D>` | Double-width |
176
- | `<DB>...</DB>` | Double-width bold |
177
- | `<M>...</M>` | Medium (double-height) |
178
+ ### Text Style
178
179
 
179
- Example:
180
+ | Tag | Description |
181
+ | ---------------------- | ---------------------------------------------------- |
182
+ | `<BOLD>...</BOLD>` | Bold / emphasis (no size change) |
183
+ | `<U>...</U>` | Underline (1-dot thin) |
184
+ | `<U2>...</U2>` | Underline (2-dot thick) |
185
+ | `<REV>...</REV>` | Reverse (white text on black background) |
186
+ | `<UPDOWN>...</UPDOWN>` | Upside-down printing |
187
+
188
+ ### Font Selection
189
+
190
+ | Tag | Description |
191
+ | ----------- | ------------------------------------------------------- |
192
+ | `<FONT_A>` | Select Font A — default, typically 12×24 dots |
193
+ | `<FONT_B>` | Select Font B — smaller, typically 9×17 dots |
194
+
195
+ ### Text Alignment
196
+
197
+ | Tag | Description |
198
+ | ------------ | -------------- |
199
+ | `<L>...</L>` | Left-aligned |
200
+ | `<C>...</C>` | Center-aligned |
201
+ | `<R>...</R>` | Right-aligned |
202
+
203
+ ### Font Size — Presets
204
+
205
+ These use the **GS !** command for clean size multipliers (1×–8×).
206
+
207
+ | Tag | Width | Height | Description |
208
+ | -------------- | :---: | :----: | ------------------ |
209
+ | `<W2>...</W2>` | 2× | 1× | Wide |
210
+ | `<W3>...</W3>` | 3× | 1× | Extra-wide |
211
+ | `<H2>...</H2>` | 1× | 2× | Tall |
212
+ | `<H3>...</H3>` | 1× | 3× | Extra-tall |
213
+ | `<X2>...</X2>` | 2× | 2× | Double size |
214
+ | `<X3>...</X3>` | 3× | 3× | Triple size |
215
+ | `<X4>...</X4>` | 4× | 4× | Quadruple size |
216
+
217
+ ### Font Size — Custom
218
+
219
+ Use `<FS:W,H>` for arbitrary width/height multipliers (1–8):
220
+
221
+ ```
222
+ <FS:2,3>Big text</FS> ← width ×2, height ×3
223
+ <FS:1,5>Very tall</FS> ← width ×1, height ×5
224
+ <FS:8,8>Maximum size</FS> ← width ×8, height ×8
225
+ ```
226
+
227
+ ### Spacing Control
228
+
229
+ | Tag | Description |
230
+ | ----------------------- | ------------------------------------------------------------ |
231
+ | `<LINESPC:N>` | Set line spacing to N dots (0–255). Close with `</LINESPC>`. |
232
+ | `<CHARSPC:N>` | Set character spacing to N dots (0–255). Close with `</CHARSPC>`. |
233
+
234
+ ### Legacy Size Tags
235
+
236
+ These use the older **ESC !** command and are kept for backward compatibility.
237
+
238
+ | Tag | Description |
239
+ | -------------- | ---------------------------------------- |
240
+ | `<B>...</B>` | Big (double-height + double-width) |
241
+ | `<D>...</D>` | Double-width |
242
+ | `<DB>...</DB>` | Double-width + bold emphasis |
243
+ | `<M>...</M>` | Medium (double-height) |
244
+ | `<CM>...</CM>` | Center + medium |
245
+ | `<CB>...</CB>` | Center + big |
246
+ | `<CD>...</CD>` | Center + double-width |
247
+
248
+ ### Actions & Utilities
249
+
250
+ | Tag | Description |
251
+ | ------------ | ------------------------------------------------- |
252
+ | `<PARTCUT>` | Partial paper cut (mid-document) |
253
+ | `<DRAWER>` | Open cash drawer (ESC p pulse) |
254
+ | `<TAB>` | Insert horizontal tab (0x09) |
255
+ | `<FEED:N>` | Feed N blank lines (1–255) |
256
+ | `<RESET>` | Reset all formatting to defaults |
257
+
258
+ ### Raw Bytes
259
+
260
+ For power users who need direct ESC/POS control:
261
+
262
+ ```
263
+ <RAW:1B,40> ← sends ESC @ (initialize printer)
264
+ <RAW:1D,56,00> ← sends GS V 0 (full cut, alternative)
265
+ ```
266
+
267
+ ### Combining Tags
268
+
269
+ Tags can be freely combined on the same line:
180
270
 
181
271
  ```tsx
182
272
  await NetPrinter.printBill(
183
- "<C><B>MY STORE</B></C>\n" +
184
- "================================\n" +
185
- "Item 1 $5.00\n" +
186
- "Item 2 $3.50\n" +
187
- "================================\n" +
188
- "<B>TOTAL $8.50</B>\n",
273
+ "<C><BOLD><X2>MY STORE</X2></BOLD></C>\n" +
274
+ "<C><U>================================</U></C>\n" +
275
+ "<FONT_B>Item 1 $5.00\n" +
276
+ "Item 2 $3.50\n" +
277
+ "<FONT_A><BOLD>================================</BOLD>\n" +
278
+ "<R><FS:2,2>TOTAL $8.50</FS></R>\n" +
279
+ "<C><REV> THANK YOU! </REV></C>\n"
189
280
  );
190
281
  ```
191
282
 
@@ -351,7 +442,7 @@ export default function ThermalPrinterTest() {
351
442
 
352
443
  try {
353
444
  // To print a QR code:
354
- await BLEPrinter.printQrCode("ZAM-OC-0001");
445
+ await BLEPrinter.printQrCode("ZAM-OC-0001", 100); // qrSize
355
446
  // Print formatted receipt text (beeps + cuts automatically)
356
447
  const bill =
357
448
  "--------------------------------\n" +
@@ -364,8 +455,9 @@ export default function ThermalPrinterTest() {
364
455
 
365
456
  // To print an image from URL:
366
457
  // await BLEPrinter.printImage(
367
- // "https://images.unsplash.com/photo-1771258052747-52e19364185f?q=80&w=765&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
368
- // );
458
+ "https://images.unsplash.com/photo-1771258052747-52e19364185f?q=80&w=765&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
459
+ 300, // imageWidth
460
+ );
369
461
  } catch (err) {
370
462
  console.warn("Print error:", err);
371
463
  Alert.alert("Print Error", String(err));
package/android/.project CHANGED
@@ -5,11 +5,6 @@
5
5
  <projects>
6
6
  </projects>
7
7
  <buildSpec>
8
- <buildCommand>
9
- <name>org.eclipse.jdt.core.javabuilder</name>
10
- <arguments>
11
- </arguments>
12
- </buildCommand>
13
8
  <buildCommand>
14
9
  <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15
10
  <arguments>
@@ -17,7 +12,6 @@
17
12
  </buildCommand>
18
13
  </buildSpec>
19
14
  <natures>
20
- <nature>org.eclipse.jdt.core.javanature</nature>
21
15
  <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22
16
  </natures>
23
17
  <filteredResources>
@@ -65,14 +65,14 @@ public class RNBLEPrinterModule extends NativeBLEPrinterSpec implements RNPrinte
65
65
 
66
66
  @Override
67
67
  @ReactMethod
68
- public void printImageData(String imageUrl, Promise promise) {
69
- adapter.printImageData(imageUrl, promise);
68
+ public void printImageData(String imageUrl, double imageWidth, Promise promise) {
69
+ adapter.printImageData(imageUrl, imageWidth, promise);
70
70
  }
71
71
 
72
72
  @Override
73
73
  @ReactMethod
74
- public void printQrCode(String qrCode, Promise promise) {
75
- adapter.printQrCode(qrCode, promise);
74
+ public void printQrCode(String qrCode, double qrSize, Promise promise) {
75
+ adapter.printQrCode(qrCode, qrSize, promise);
76
76
  }
77
77
 
78
78
  @Override
@@ -71,14 +71,14 @@ public class RNNetPrinterModule extends NativeNetPrinterSpec implements RNPrinte
71
71
 
72
72
  @Override
73
73
  @ReactMethod
74
- public void printImageData(String imageUrl, Promise promise) {
75
- adapter.printImageData(imageUrl, promise);
74
+ public void printImageData(String imageUrl, double imageWidth, Promise promise) {
75
+ adapter.printImageData(imageUrl, imageWidth, promise);
76
76
  }
77
77
 
78
78
  @Override
79
79
  @ReactMethod
80
- public void printQrCode(String qrCode, Promise promise) {
81
- adapter.printQrCode(qrCode, promise);
80
+ public void printQrCode(String qrCode, double qrSize, Promise promise) {
81
+ adapter.printQrCode(qrCode, qrSize, promise);
82
82
  }
83
83
 
84
84
  @Override
@@ -17,8 +17,8 @@ public interface RNPrinterModule {
17
17
 
18
18
  void printRawData(String base64Data, Promise promise);
19
19
 
20
- void printImageData(String imageUrl, Promise promise);
20
+ void printImageData(String imageUrl, double imageWidth, Promise promise);
21
21
 
22
- void printQrCode(String qrCode, Promise promise);
22
+ void printQrCode(String qrCode, double qrSize, Promise promise);
23
23
  }
24
24
 
@@ -67,13 +67,13 @@ public class RNUSBPrinterModule extends NativeUSBPrinterSpec implements RNPrinte
67
67
 
68
68
  @Override
69
69
  @ReactMethod
70
- public void printImageData(String imageUrl, Promise promise) {
71
- adapter.printImageData(imageUrl, promise);
70
+ public void printImageData(String imageUrl, double imageWidth, Promise promise) {
71
+ adapter.printImageData(imageUrl, imageWidth, promise);
72
72
  }
73
73
 
74
74
  @Override
75
75
  @ReactMethod
76
- public void printQrCode(String qrCode, Promise promise) {
77
- adapter.printQrCode(qrCode, promise);
76
+ public void printQrCode(String qrCode, double qrSize, Promise promise) {
77
+ adapter.printQrCode(qrCode, qrSize, promise);
78
78
  }
79
79
  }
@@ -210,7 +210,7 @@ public class BLEPrinterAdapter implements PrinterAdapter {
210
210
  }
211
211
 
212
212
  @Override
213
- public void printImageData(String imageUrl, Promise promise) {
213
+ public void printImageData(String imageUrl, double imageWidth, Promise promise) {
214
214
  final Bitmap bitmapImage = getBitmapFromURL(imageUrl);
215
215
 
216
216
  if (bitmapImage == null) {
@@ -223,9 +223,10 @@ public class BLEPrinterAdapter implements PrinterAdapter {
223
223
  }
224
224
 
225
225
  final BluetoothSocket socket = this.mBluetoothSocket;
226
+ final int maxSize = imageWidth > 0 ? (int) imageWidth : 200;
226
227
 
227
228
  try {
228
- int[][] pixels = getPixelsSlow(bitmapImage);
229
+ int[][] pixels = getPixelsSlow(bitmapImage, maxSize);
229
230
  OutputStream printerOutputStream = socket.getOutputStream();
230
231
 
231
232
  printerOutputStream.write(SET_LINE_SPACE_24);
@@ -252,8 +253,9 @@ public class BLEPrinterAdapter implements PrinterAdapter {
252
253
  }
253
254
 
254
255
  @Override
255
- public void printQrCode(String qrCode, Promise promise) {
256
- final Bitmap bitmapImage = TextToQrImageEncode(qrCode);
256
+ public void printQrCode(String qrCode, double qrSize, Promise promise) {
257
+ final int size = qrSize > 0 ? (int) qrSize : 250;
258
+ final Bitmap bitmapImage = TextToQrImageEncode(qrCode, size);
257
259
 
258
260
  if (bitmapImage == null) {
259
261
  promise.reject("ERR_QR", "QR code generation failed");
@@ -267,7 +269,7 @@ public class BLEPrinterAdapter implements PrinterAdapter {
267
269
  final BluetoothSocket socket = this.mBluetoothSocket;
268
270
 
269
271
  try {
270
- int[][] pixels = getPixelsSlow(bitmapImage);
272
+ int[][] pixels = getPixelsSlow(bitmapImage, size);
271
273
  OutputStream printerOutputStream = socket.getOutputStream();
272
274
 
273
275
  printerOutputStream.write(SET_LINE_SPACE_24);
@@ -293,14 +295,14 @@ public class BLEPrinterAdapter implements PrinterAdapter {
293
295
  }
294
296
  }
295
297
 
296
- private Bitmap TextToQrImageEncode(String Value) {
298
+ private Bitmap TextToQrImageEncode(String Value, int size) {
297
299
  com.google.zxing.Writer writer = new QRCodeWriter();
298
300
  BitMatrix bitMatrix = null;
299
301
  try {
300
- bitMatrix = writer.encode(Value, com.google.zxing.BarcodeFormat.QR_CODE, 250, 250,
302
+ bitMatrix = writer.encode(Value, com.google.zxing.BarcodeFormat.QR_CODE, size, size,
301
303
  ImmutableMap.of(EncodeHintType.MARGIN, 1));
302
- int width = 250;
303
- int height = 250;
304
+ int width = size;
305
+ int height = size;
304
306
  Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
305
307
 
306
308
  for (int i = 0; i < width; i++) {
@@ -314,8 +316,8 @@ public class BLEPrinterAdapter implements PrinterAdapter {
314
316
  }
315
317
  }
316
318
 
317
- public static int[][] getPixelsSlow(Bitmap image2) {
318
- Bitmap image = resizeTheImageForPrinting(image2);
319
+ public static int[][] getPixelsSlow(Bitmap image2, int maxSize) {
320
+ Bitmap image = resizeTheImageForPrinting(image2, maxSize);
319
321
  int width = image.getWidth();
320
322
  int height = image.getHeight();
321
323
  int[][] result = new int[height][width];
@@ -360,15 +362,15 @@ public class BLEPrinterAdapter implements PrinterAdapter {
360
362
  return luminance < threshold;
361
363
  }
362
364
 
363
- public static Bitmap resizeTheImageForPrinting(Bitmap image) {
365
+ public static Bitmap resizeTheImageForPrinting(Bitmap image, int maxSize) {
364
366
  int width = image.getWidth();
365
367
  int height = image.getHeight();
366
- if (width > 200 || height > 200) {
368
+ if (width > maxSize || height > maxSize) {
367
369
  if (width > height) {
368
- float decreaseSizeBy = (200.0f / width);
370
+ float decreaseSizeBy = ((float) maxSize / width);
369
371
  return getBitmapResized(image, decreaseSizeBy);
370
372
  } else {
371
- float decreaseSizeBy = (200.0f / height);
373
+ float decreaseSizeBy = ((float) maxSize / height);
372
374
  return getBitmapResized(image, decreaseSizeBy);
373
375
  }
374
376
  }
@@ -250,7 +250,7 @@ public class NetPrinterAdapter implements PrinterAdapter {
250
250
  }
251
251
 
252
252
  @Override
253
- public void printImageData(final String imageUrl, Promise promise) {
253
+ public void printImageData(final String imageUrl, double imageWidth, Promise promise) {
254
254
  final Bitmap bitmapImage = getBitmapFromURL(imageUrl);
255
255
 
256
256
  if (bitmapImage == null) {
@@ -264,9 +264,10 @@ public class NetPrinterAdapter implements PrinterAdapter {
264
264
  }
265
265
 
266
266
  final Socket socket = this.mSocket;
267
+ final int maxSize = imageWidth > 0 ? (int) imageWidth : 200;
267
268
 
268
269
  try {
269
- int[][] pixels = getPixelsSlow(bitmapImage);
270
+ int[][] pixels = getPixelsSlow(bitmapImage, maxSize);
270
271
  OutputStream printerOutputStream = socket.getOutputStream();
271
272
 
272
273
  printerOutputStream.write(SET_LINE_SPACE_24);
@@ -293,8 +294,9 @@ public class NetPrinterAdapter implements PrinterAdapter {
293
294
  }
294
295
 
295
296
  @Override
296
- public void printQrCode(String qrCode, Promise promise) {
297
- final Bitmap bitmapImage = TextToQrImageEncode(qrCode);
297
+ public void printQrCode(String qrCode, double qrSize, Promise promise) {
298
+ final int size = qrSize > 0 ? (int) qrSize : 250;
299
+ final Bitmap bitmapImage = TextToQrImageEncode(qrCode, size);
298
300
 
299
301
  if (bitmapImage == null) {
300
302
  promise.reject("ERR_QR", "QR code generation failed");
@@ -309,7 +311,7 @@ public class NetPrinterAdapter implements PrinterAdapter {
309
311
  final Socket socket = this.mSocket;
310
312
 
311
313
  try {
312
- int[][] pixels = getPixelsSlow(bitmapImage);
314
+ int[][] pixels = getPixelsSlow(bitmapImage, size);
313
315
  OutputStream printerOutputStream = socket.getOutputStream();
314
316
 
315
317
  printerOutputStream.write(SET_LINE_SPACE_24);
@@ -335,14 +337,14 @@ public class NetPrinterAdapter implements PrinterAdapter {
335
337
  }
336
338
  }
337
339
 
338
- private Bitmap TextToQrImageEncode(String Value) {
340
+ private Bitmap TextToQrImageEncode(String Value, int size) {
339
341
  com.google.zxing.Writer writer = new QRCodeWriter();
340
342
  BitMatrix bitMatrix = null;
341
343
  try {
342
- bitMatrix = writer.encode(Value, com.google.zxing.BarcodeFormat.QR_CODE, 250, 250,
344
+ bitMatrix = writer.encode(Value, com.google.zxing.BarcodeFormat.QR_CODE, size, size,
343
345
  ImmutableMap.of(EncodeHintType.MARGIN, 1));
344
- int width = 250;
345
- int height = 250;
346
+ int width = size;
347
+ int height = size;
346
348
  Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
347
349
 
348
350
  for (int i = 0; i < width; i++) {
@@ -356,8 +358,8 @@ public class NetPrinterAdapter implements PrinterAdapter {
356
358
  }
357
359
  }
358
360
 
359
- public static int[][] getPixelsSlow(Bitmap image2) {
360
- Bitmap image = resizeTheImageForPrinting(image2);
361
+ public static int[][] getPixelsSlow(Bitmap image2, int maxSize) {
362
+ Bitmap image = resizeTheImageForPrinting(image2, maxSize);
361
363
  int width = image.getWidth();
362
364
  int height = image.getHeight();
363
365
  int[][] result = new int[height][width];
@@ -402,15 +404,15 @@ public class NetPrinterAdapter implements PrinterAdapter {
402
404
  return luminance < threshold;
403
405
  }
404
406
 
405
- public static Bitmap resizeTheImageForPrinting(Bitmap image) {
407
+ public static Bitmap resizeTheImageForPrinting(Bitmap image, int maxSize) {
406
408
  int width = image.getWidth();
407
409
  int height = image.getHeight();
408
- if (width > 200 || height > 200) {
410
+ if (width > maxSize || height > maxSize) {
409
411
  if (width > height) {
410
- float decreaseSizeBy = (200.0f / width);
412
+ float decreaseSizeBy = ((float) maxSize / width);
411
413
  return getBitmapResized(image, decreaseSizeBy);
412
414
  } else {
413
- float decreaseSizeBy = (200.0f / height);
415
+ float decreaseSizeBy = ((float) maxSize / height);
414
416
  return getBitmapResized(image, decreaseSizeBy);
415
417
  }
416
418
  }
@@ -23,7 +23,7 @@ public interface PrinterAdapter {
23
23
 
24
24
  void printRawData(String rawBase64Data, Promise promise);
25
25
 
26
- void printImageData(String imageUrl, Promise promise);
26
+ void printImageData(String imageUrl, double imageWidth, Promise promise);
27
27
 
28
- void printQrCode(String qrCode, Promise promise);
28
+ void printQrCode(String qrCode, double qrSize, Promise promise);
29
29
  }
@@ -275,7 +275,7 @@ public class USBPrinterAdapter implements PrinterAdapter {
275
275
  }
276
276
 
277
277
  @Override
278
- public void printImageData(final String imageUrl, Promise promise) {
278
+ public void printImageData(final String imageUrl, double imageWidth, Promise promise) {
279
279
  final Bitmap bitmapImage = getBitmapFromURL(imageUrl);
280
280
 
281
281
  if (bitmapImage == null) {
@@ -288,7 +288,8 @@ public class USBPrinterAdapter implements PrinterAdapter {
288
288
  if (isConnected) {
289
289
  Log.v(LOG_TAG, "Connected to device");
290
290
  try {
291
- int[][] pixels = getPixelsSlow(bitmapImage);
291
+ final int maxSize = imageWidth > 0 ? (int) imageWidth : 200;
292
+ int[][] pixels = getPixelsSlow(bitmapImage, maxSize);
292
293
 
293
294
  mUsbDeviceConnection.bulkTransfer(mEndPoint, SET_LINE_SPACE_24, SET_LINE_SPACE_24.length, 100000);
294
295
  mUsbDeviceConnection.bulkTransfer(mEndPoint, CENTER_ALIGN, CENTER_ALIGN.length, 100000);
@@ -322,14 +323,14 @@ public class USBPrinterAdapter implements PrinterAdapter {
322
323
  }
323
324
  }
324
325
 
325
- private Bitmap TextToQrImageEncode(String Value) {
326
+ private Bitmap TextToQrImageEncode(String Value, int size) {
326
327
  com.google.zxing.Writer writer = new QRCodeWriter();
327
328
  BitMatrix bitMatrix = null;
328
329
  try {
329
- bitMatrix = writer.encode(Value, com.google.zxing.BarcodeFormat.QR_CODE, 250, 250,
330
+ bitMatrix = writer.encode(Value, com.google.zxing.BarcodeFormat.QR_CODE, size, size,
330
331
  ImmutableMap.of(EncodeHintType.MARGIN, 1));
331
- int width = 250;
332
- int height = 250;
332
+ int width = size;
333
+ int height = size;
333
334
  Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
334
335
 
335
336
  for (int i = 0; i < width; i++) {
@@ -344,8 +345,9 @@ public class USBPrinterAdapter implements PrinterAdapter {
344
345
  }
345
346
 
346
347
  @Override
347
- public void printQrCode(String qrCode, Promise promise) {
348
- final Bitmap bitmapImage = TextToQrImageEncode(qrCode);
348
+ public void printQrCode(String qrCode, double qrSize, Promise promise) {
349
+ final int size = qrSize > 0 ? (int) qrSize : 250;
350
+ final Bitmap bitmapImage = TextToQrImageEncode(qrCode, size);
349
351
 
350
352
  if (bitmapImage == null) {
351
353
  promise.reject("ERR_QR", "QR code generation failed");
@@ -357,7 +359,7 @@ public class USBPrinterAdapter implements PrinterAdapter {
357
359
  if (isConnected) {
358
360
  Log.v(LOG_TAG, "Connected to device");
359
361
  try {
360
- int[][] pixels = getPixelsSlow(bitmapImage);
362
+ int[][] pixels = getPixelsSlow(bitmapImage, size);
361
363
 
362
364
  mUsbDeviceConnection.bulkTransfer(mEndPoint, SET_LINE_SPACE_24, SET_LINE_SPACE_24.length, 100000);
363
365
  mUsbDeviceConnection.bulkTransfer(mEndPoint, CENTER_ALIGN, CENTER_ALIGN.length, 100000);
@@ -391,8 +393,8 @@ public class USBPrinterAdapter implements PrinterAdapter {
391
393
  }
392
394
  }
393
395
 
394
- public static int[][] getPixelsSlow(Bitmap image2) {
395
- Bitmap image = resizeTheImageForPrinting(image2);
396
+ public static int[][] getPixelsSlow(Bitmap image2, int maxSize) {
397
+ Bitmap image = resizeTheImageForPrinting(image2, maxSize);
396
398
  int width = image.getWidth();
397
399
  int height = image.getHeight();
398
400
  int[][] result = new int[height][width];
@@ -437,15 +439,15 @@ public class USBPrinterAdapter implements PrinterAdapter {
437
439
  return luminance < threshold;
438
440
  }
439
441
 
440
- public static Bitmap resizeTheImageForPrinting(Bitmap image) {
442
+ public static Bitmap resizeTheImageForPrinting(Bitmap image, int maxSize) {
441
443
  int width = image.getWidth();
442
444
  int height = image.getHeight();
443
- if (width > 200 || height > 200) {
445
+ if (width > maxSize || height > maxSize) {
444
446
  if (width > height) {
445
- float decreaseSizeBy = (200.0f / width);
447
+ float decreaseSizeBy = ((float) maxSize / width);
446
448
  return getBitmapResized(image, decreaseSizeBy);
447
449
  } else {
448
- float decreaseSizeBy = (200.0f / height);
450
+ float decreaseSizeBy = ((float) maxSize / height);
449
451
  return getBitmapResized(image, decreaseSizeBy);
450
452
  }
451
453
  }
@@ -5,8 +5,8 @@ export interface Spec extends TurboModule {
5
5
  connectPrinter(innerAddress: string): Promise<Object>;
6
6
  closeConn(): void;
7
7
  printRawData(base64Data: string): Promise<void>;
8
- printImageData(imageUrl: string): Promise<void>;
9
- printQrCode(qrCode: string): Promise<void>;
8
+ printImageData(imageUrl: string, imageWidth: number): Promise<void>;
9
+ printQrCode(qrCode: string, qrSize: number): Promise<void>;
10
10
  addListener(eventName: string): void;
11
11
  removeListeners(count: number): void;
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NativeBLEPrinter.d.ts","sourceRoot":"","sources":["../src/NativeBLEPrinter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAA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,CAAC,CAAC;IAC3D,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;;AAED,wBAAsE"}
@@ -5,8 +5,8 @@ export interface Spec extends TurboModule {
5
5
  connectPrinter(host: string, port: number): Promise<Object>;
6
6
  closeConn(): void;
7
7
  printRawData(base64Data: string): Promise<void>;
8
- printImageData(imageUrl: string): Promise<void>;
9
- printQrCode(qrCode: string): Promise<void>;
8
+ printImageData(imageUrl: string, imageWidth: number): Promise<void>;
9
+ printQrCode(qrCode: string, qrSize: number): Promise<void>;
10
10
  addListener(eventName: string): void;
11
11
  removeListeners(count: number): void;
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NativeNetPrinter.d.ts","sourceRoot":"","sources":["../src/NativeNetPrinter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACxC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACnC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5D,SAAS,IAAI,IAAI,CAAC;IAClB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;;AAED,wBAAsE"}
1
+ {"version":3,"file":"NativeNetPrinter.d.ts","sourceRoot":"","sources":["../src/NativeNetPrinter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACxC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACnC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5D,SAAS,IAAI,IAAI,CAAC;IAClB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;;AAED,wBAAsE"}
@@ -5,8 +5,8 @@ export interface Spec extends TurboModule {
5
5
  connectPrinter(vendorId: number, productId: number): Promise<Object>;
6
6
  closeConn(): void;
7
7
  printRawData(base64Data: string): Promise<void>;
8
- printImageData(imageUrl: string): Promise<void>;
9
- printQrCode(qrCode: string): Promise<void>;
8
+ printImageData(imageUrl: string, imageWidth: number): Promise<void>;
9
+ printQrCode(qrCode: string, qrSize: number): Promise<void>;
10
10
  }
11
11
  declare const _default: Spec;
12
12
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"NativeUSBPrinter.d.ts","sourceRoot":"","sources":["../src/NativeUSBPrinter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,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/index.d.ts CHANGED
@@ -27,8 +27,8 @@ export declare const USBPrinter: {
27
27
  closeConn: () => void;
28
28
  printText: (text: string, opts?: PrinterOptions) => Promise<void>;
29
29
  printBill: (text: string, opts?: PrinterOptions) => Promise<void>;
30
- printImage: (imageUrl: string) => Promise<void>;
31
- printQrCode: (qrCode: string) => Promise<void>;
30
+ printImage: (imageUrl: string, imageWidth?: number) => Promise<void>;
31
+ printQrCode: (qrCode: string, qrSize?: number) => Promise<void>;
32
32
  };
33
33
  export declare const BLEPrinter: {
34
34
  init: () => Promise<string>;
@@ -37,8 +37,8 @@ export declare const BLEPrinter: {
37
37
  closeConn: () => void;
38
38
  printText: (text: string, opts?: PrinterOptions) => Promise<void>;
39
39
  printBill: (text: string, opts?: PrinterOptions) => Promise<void>;
40
- printImage: (imageUrl: string) => Promise<void>;
41
- printQrCode: (qrCode: string) => Promise<void>;
40
+ printImage: (imageUrl: string, imageWidth?: number) => Promise<void>;
41
+ printQrCode: (qrCode: string, qrSize?: number) => Promise<void>;
42
42
  };
43
43
  export declare const NetPrinter: {
44
44
  init: () => Promise<string>;
@@ -47,8 +47,8 @@ export declare const NetPrinter: {
47
47
  closeConn: () => void;
48
48
  printText: (text: string, opts?: PrinterOptions) => Promise<void>;
49
49
  printBill: (text: string, opts?: PrinterOptions) => Promise<void>;
50
- printImage: (imageUrl: string) => Promise<void>;
51
- printQrCode: (qrCode: string) => Promise<void>;
50
+ printImage: (imageUrl: string, imageWidth?: number) => Promise<void>;
51
+ printQrCode: (qrCode: string, qrSize?: number) => Promise<void>;
52
52
  };
53
53
  export declare const NetPrinterEventEmitter: NativeEventEmitter;
54
54
  export declare enum RN_THERMAL_RECEIPT_PRINTER_EVENTS {