@rejaul/react-native-printer-kit 0.4.0 → 0.4.1

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 CHANGED
@@ -191,7 +191,63 @@ Prints a short ASCII test page (connection type, printer, address, time).
191
191
  ### Saving and opening files
192
192
 
193
193
  #### `saveFile(params: SaveFileParams): Promise<SaveFileResult>`
194
- Copies a finished file (for example the PDF from `htmlToPdf`) to `CACHE`, `APP_FILES`, public `DOWNLOADS` / `DOCUMENTS` or a `CUSTOM_FOLDER`. Never rejects: check `result.success` and `result.error`. On Android 10+ Downloads/Documents use MediaStore (no permission needed); on Android 9 and below you need `WRITE_EXTERNAL_STORAGE`. `overwrite: true` can only replace files this app created.
194
+ Saves a file to `CACHE`, `APP_FILES`, public `DOWNLOADS` / `DOCUMENTS`, the public `PICTURES` folder (shows in the Gallery; images only) or a `CUSTOM_FOLDER`. Either copy an existing file with `sourcePath` (for example the PDF from `htmlToPdf`), or **pass the content directly**: `text` (UTF-8 string) or `base64` (bytes, for images/PDFs; a `data:...;base64,` prefix is fine). Give exactly one of the three; with `text` / `base64` a `fileName` is required. Never rejects: check `result.success` and `result.error`.
195
+
196
+ ```typescript
197
+ await saveFile({ text: csv, fileName: 'report.csv', subFolder: 'MyApp' });
198
+ await saveFile({ base64: pngBase64, fileName: 'qr.png', location: FileLocation.DOCUMENTS });
199
+ ``` On Android 10+ Downloads/Documents use MediaStore (no permission needed); on Android 9 and below you need `WRITE_EXTERNAL_STORAGE`. `overwrite: true` can only replace files this app created.
200
+
201
+ #### `readFile(params: ReadFileParams): Promise<ReadFileResult>`
202
+ Reads **one** file and returns its content in the shape `format` asks for. `path` is an absolute path, or the `content://` Uri that `saveFile` returned.
203
+
204
+ | `format` | `result` holds |
205
+ |---|---|
206
+ | `'base64'` (default) | `content`: plain base64, for images, PDFs and any binary file |
207
+ | `'dataUri'` | `content`: `data:<type>;base64,...` (type from the file extension), ready for an `<Image>`/`<img>` or an upload |
208
+ | `'text'` | `content`: the file decoded as text (UTF-8, or `encoding: 'UTF-16'`, `'ISO-8859-1'`, ...). Only meaningful for text files |
209
+ | `'hex'` | `content`: lower-case hex, two digits per byte |
210
+ | `'bytes'` | `bytes`: array of numbers 0–255. Heavy, so **capped at 1 MB** |
211
+
212
+ Also returned: `sizeBytes` and `mimeType`. The whole file is loaded into memory, so a file over `maxBytes` (default **10 MB**) is refused with a clear message instead. Never rejects: check `result.success` and `result.error`. For JSON, read it as `'text'` and `JSON.parse` it.
213
+
214
+ ```typescript
215
+ const r = await readFile({ path: imagePath, format: 'base64' });
216
+ if (r.success) await upload(r.content!); // "iVBORw0KGgo..."
217
+
218
+ const pdf = await readFile({ path: pdfPath, format: 'dataUri' });
219
+ // pdf.content = "data:application/pdf;base64,JVBERi0x..."
220
+ ```
221
+
222
+ #### `htmlToImage(params: HtmlToImageParams): Promise<string | null>`
223
+ Renders HTML to **one** image file and returns its path, or `null` on failure. It is `htmlToPdf` plus one rendered page: `imageType` is `'PNG'` (default) or `'JPEG'`, `targetWidthPx` is the image width (default: twice the page width), `outputPath` chooses the full file path (folder must exist), and `pageWidthDp` / `heightDp` / `minPageHeightDp` work as in `htmlToPdf`. A **very tall page makes a very large bitmap and can run out of memory**, in which case you get `null`. For base64, pass the returned path to `readFile`.
224
+
225
+ ```typescript
226
+ const png = await htmlToImage({ html: receiptHtml, targetWidthPx: 800 });
227
+ if (png) {
228
+ const b64 = await readFile({ path: png, format: 'base64' }); // send to your server
229
+ await saveFile({ sourcePath: png, fileName: 'receipt.png', location: FileLocation.PICTURES }); // Gallery
230
+ }
231
+ ```
232
+
233
+ #### `readDir(params: ReadDirParams): Promise<ReadDirResult>`
234
+ Reads **one** folder: the files and folders directly inside it, **folders first, then A–Z**. `path` is an absolute folder path, or the `content://` Uri of a folder the user picked with the system folder picker. `result.names` is just the names; `result.entries` has `name`, `path`, `isDirectory`, `sizeBytes` (`null` for a folder) and `lastModified`. It does not go into sub-folders: call it again with an entry's `path` to go deeper, and an entry's `path` also works with `removeFile`. A path that is a file, is missing or is relative is refused. Android 10+ restricts reading public folders such as Downloads, so for those the result may say the folder cannot be read; the app's own folders and a folder picked with the system folder picker always work. Never rejects: check `result.success` and `result.error`.
235
+
236
+ ```typescript
237
+ const dir = await readDir({ path: '/data/user/0/<your.app>/files' });
238
+ if (dir.success) {
239
+ console.log(dir.names); // ['reports', 'logo.png', 'notes.txt']
240
+ const folders = dir.entries.filter((e) => e.isDirectory);
241
+ }
242
+ ```
243
+
244
+ #### `removeFile(params: RemoveFileParams): Promise<RemoveFileResult>`
245
+ Deletes **one** file: an absolute `path`, or the `content://` Uri that `saveFile` returned. It never deletes a folder, never expands a pattern, refuses a relative path, and **cannot be undone**. A missing file is reported as a failure (`"File not found"`), which you can ignore if you only wanted it gone. On Android 10+ a file in Downloads/Documents (a MediaStore Uri) can only be deleted if your app created it. Never rejects: check `result.success` and `result.error`.
246
+
247
+ ```typescript
248
+ const saved = await saveFile({ text: 'temp', fileName: 'tmp.txt' });
249
+ if (saved.success) await removeFile({ path: saved.path ?? saved.uri! });
250
+ ```
195
251
 
196
252
  #### `openFile(params: OpenFileParams): boolean`
197
253
  Opens a file with whatever installed app can handle its type (shows the "Open with" chooser if several match). Returns `false` if the file does not exist or no app can open it.
@@ -219,7 +275,7 @@ Renders one PDF page to an image file and returns its path.
219
275
  `pdfToImage` + print, in one call.
220
276
 
221
277
  #### `htmlToPdf(params: HtmlToPdfParams): Promise<string | null>`
222
- 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).
278
+ Renders HTML to a PDF file using an off-screen `WebView` and returns its path, or `null` on failure. Pass `outputPath` (the full path including the file name, e.g. `/data/user/0/<your.app>/files/invoice.pdf`) to choose where the PDF goes; without it you get a generated name in the app's cache folder. `outputPath` must be in a folder that already exists and that your app can write to (its own files/cache folders), and an existing file is overwritten. To end up in a public folder such as Downloads, convert first and then call [`saveFile`](#savefileparams-savefileparams-promisesavefileresult), which accepts `fileName`, `location` and `subFolder`. `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).
223
279
 
224
280
  #### `printHtml(params: PrintHtmlParams): Promise<boolean>`
225
281
  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.
@@ -234,7 +290,8 @@ import {
234
290
  PrinterConfidence, // CONFIDENT | LIKELY | UNKNOWN
235
291
  PrinterConnectionType, // BLUETOOTH | NETWORK | USB
236
292
  PrinterImageType, // PNG | JPEG
237
- FileLocation, // CACHE | APP_FILES | DOWNLOADS | DOCUMENTS | CUSTOM_FOLDER
293
+ FileLocation, // CACHE | APP_FILES | DOWNLOADS | DOCUMENTS | PICTURES | CUSTOM_FOLDER
294
+ ReadFileFormat, // base64 | dataUri | text | hex | bytes
238
295
  } from '@rejaul/react-native-printer-kit';
239
296
 
240
297
  getBondedBluetoothPrinters({ filter: PrinterFilter.LIKELY_PRINTERS });
@@ -301,11 +358,14 @@ type FileLocation =
301
358
  | 'APP_FILES'
302
359
  | 'DOWNLOADS'
303
360
  | 'DOCUMENTS'
361
+ | 'PICTURES' // public Pictures folder: shows in the Gallery. Images only.
304
362
  | 'CUSTOM_FOLDER';
305
363
 
306
364
  type SaveFileParams = {
307
- sourcePath: string;
308
- fileName?: string; // defaults to the source file's name
365
+ sourcePath?: string; // an existing file ... OR text / base64 below (exactly one)
366
+ text?: string; // content as UTF-8 text; needs fileName
367
+ base64?: string; // content as base64 bytes; needs fileName
368
+ fileName?: string; // defaults to the source file's name; required with text/base64
309
369
  location?: FileLocation; // default 'DOWNLOADS'
310
370
  customFolder?: string; // required for CUSTOM_FOLDER
311
371
  subFolder?: string;
@@ -322,6 +382,63 @@ type SaveFileResult = {
322
382
  error: string | null;
323
383
  };
324
384
 
385
+ type ReadFileFormat = 'base64' | 'dataUri' | 'text' | 'hex' | 'bytes';
386
+
387
+ type ReadFileParams = {
388
+ path: string; // absolute path, or a content:// Uri
389
+ format?: ReadFileFormat; // default 'base64'
390
+ encoding?: string; // 'text' only; default 'UTF-8'
391
+ maxBytes?: number; // default 10 MB; 'bytes' is always capped at 1 MB
392
+ };
393
+
394
+ type ReadFileResult = {
395
+ success: boolean;
396
+ format: ReadFileFormat | null;
397
+ content: string | null; // base64 / dataUri / text / hex
398
+ bytes: number[] | null; // bytes
399
+ sizeBytes: number | null;
400
+ mimeType: string | null;
401
+ error: string | null;
402
+ };
403
+
404
+ type HtmlToImageParams = {
405
+ html: string;
406
+ outputPath?: string; // full path incl. file name; default: generated name in the cache folder
407
+ imageType?: PrinterImageType; // default 'PNG'
408
+ targetWidthPx?: number; // default: twice the page width
409
+ pageWidthDp?: number;
410
+ heightDp?: number;
411
+ minPageHeightDp?: number;
412
+ };
413
+
414
+ type ReadDirParams = { path: string }; // absolute folder path, or a folder content:// Uri
415
+
416
+ type DirEntry = {
417
+ name: string;
418
+ path: string; // works with removeFile (a file) or readDir (a folder)
419
+ isDirectory: boolean;
420
+ sizeBytes: number | null; // null for a folder
421
+ lastModified: number | null; // ms since 1970
422
+ };
423
+
424
+ type ReadDirResult = {
425
+ success: boolean;
426
+ path: string | null;
427
+ names: string[];
428
+ entries: DirEntry[];
429
+ error: string | null;
430
+ };
431
+
432
+ type RemoveFileParams = { path: string }; // absolute path, or a content:// Uri from saveFile
433
+
434
+ type RemoveFileResult = {
435
+ success: boolean;
436
+ path: string | null;
437
+ uri: string | null;
438
+ fileName: string | null;
439
+ error: string | null;
440
+ };
441
+
325
442
  type OpenFileParams = { path: string; mimeType?: string };
326
443
 
327
444
  type PrintTextParams = { text: string; feedLines?: number };
@@ -360,6 +477,7 @@ type PrintPdfParams = {
360
477
 
361
478
  type HtmlToPdfParams = {
362
479
  html: string;
480
+ outputPath?: string; // full path incl. file name; default: generated name in the cache folder
363
481
  pageWidthDp?: number;
364
482
  heightDp?: number;
365
483
  minPageHeightDp?: number;
@@ -61,5 +61,5 @@ repositories {
61
61
 
62
62
  dependencies {
63
63
  implementation "com.facebook.react:react-android"
64
- implementation("com.github.DeveloperRejaul:android-printer-kit:v0.1.0")
64
+ implementation("com.github.DeveloperRejaul:android-printer-kit:v0.1.1")
65
65
  }
@@ -30,6 +30,12 @@ import com.rezaul.printerkit.model.PrintTextParams
30
30
  import com.rezaul.printerkit.model.PrinterConnectionType
31
31
  import com.rezaul.printerkit.model.PrinterFilter
32
32
  import com.rezaul.printerkit.model.PrinterImageType
33
+ import com.rezaul.printerkit.model.HtmlToImageParams
34
+ import com.rezaul.printerkit.model.ReadDirParams
35
+ import com.rezaul.printerkit.model.ReadFileFormat
36
+ import com.rezaul.printerkit.model.ReadFileParams
37
+ import com.rezaul.printerkit.model.ReadFileResult
38
+ import com.rezaul.printerkit.model.RemoveFileParams
33
39
  import com.rezaul.printerkit.model.SaveFileParams
34
40
  import com.rezaul.printerkit.model.UsbPrinterDevice
35
41
  import java.util.concurrent.Executors
@@ -336,16 +342,15 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
336
342
  }
337
343
 
338
344
  override fun saveFile(params: ReadableMap, promise: Promise) {
339
- val sourcePath = params.getString("sourcePath")
340
- if (sourcePath == null) {
341
- promise.reject("ERROR", "sourcePath is required")
342
- return
343
- }
345
+ // Exactly one of sourcePath / text / base64 is validated by the native library, which
346
+ // answers with result.success = false and a message, so nothing to reject here.
344
347
  executor.execute {
345
348
  try {
346
349
  val result = standalonePrinter.saveFile(
347
350
  SaveFileParams(
348
- sourcePath = sourcePath,
351
+ sourcePath = params.optString("sourcePath"),
352
+ text = params.optString("text"),
353
+ base64 = params.optString("base64"),
349
354
  fileName = params.optString("fileName"),
350
355
  location = enumOrDefault(params.optString("location"), FileLocation.DOWNLOADS),
351
356
  customFolder = params.optString("customFolder"),
@@ -362,6 +367,92 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
362
367
  }
363
368
  }
364
369
 
370
+ override fun readFile(params: ReadableMap, promise: Promise) {
371
+ val path = params.getString("path")
372
+ if (path == null) {
373
+ promise.reject("ERROR", "path is required")
374
+ return
375
+ }
376
+ val formatName = params.optString("format")
377
+ val format = if (formatName == null) ReadFileFormat.BASE64 else ReadFileFormat.fromWireName(formatName)
378
+ if (format == null) {
379
+ // Same "never rejects" contract as the other file functions: a bad format is a failed result.
380
+ val failed = ReadFileResult(false, error = "Unknown format: $formatName (use base64, dataUri, text, hex or bytes)")
381
+ promise.resolve(Arguments.makeNativeMap(failed.toMap()))
382
+ return
383
+ }
384
+ executor.execute {
385
+ try {
386
+ val result = standalonePrinter.readFile(
387
+ ReadFileParams(
388
+ path = path,
389
+ format = format,
390
+ encoding = params.optString("encoding"),
391
+ maxBytes = params.optLong("maxBytes", ReadFileParams.DEFAULT_MAX_BYTES)
392
+ )
393
+ )
394
+ promise.resolve(Arguments.makeNativeMap(result.toMap()))
395
+ } catch (e: Exception) {
396
+ promise.reject("ERROR", e.message)
397
+ }
398
+ }
399
+ }
400
+
401
+ override fun htmlToImage(params: ReadableMap, promise: Promise) {
402
+ val html = params.getString("html")
403
+ if (html == null) {
404
+ promise.reject("ERROR", "html is required")
405
+ return
406
+ }
407
+ // htmlToImage hops to the main thread for the WebView and does the rendering on its own
408
+ // background thread, so it can be called straight from here.
409
+ standalonePrinter.htmlToImage(
410
+ HtmlToImageParams(
411
+ html = html,
412
+ outputPath = params.optString("outputPath"),
413
+ imageType = if (params.getString("imageType") == "JPEG") PrinterImageType.JPEG else PrinterImageType.PNG,
414
+ targetWidthPx = params.optIntOrNull("targetWidthPx"),
415
+ pageWidthDp = params.optInt("pageWidthDp", 412),
416
+ heightDp = params.optIntOrNull("heightDp"),
417
+ minPageHeightDp = params.optInt("minPageHeightDp", 1000)
418
+ )
419
+ ) { path ->
420
+ promise.resolve(path)
421
+ }
422
+ }
423
+
424
+ override fun readDir(params: ReadableMap, promise: Promise) {
425
+ val path = params.getString("path")
426
+ if (path == null) {
427
+ promise.reject("ERROR", "path is required")
428
+ return
429
+ }
430
+ executor.execute {
431
+ try {
432
+ val result = standalonePrinter.readDir(ReadDirParams(path))
433
+ promise.resolve(Arguments.makeNativeMap(result.toMap()))
434
+ } catch (e: Exception) {
435
+ promise.reject("ERROR", e.message)
436
+ }
437
+ }
438
+ }
439
+
440
+ override fun removeFile(params: ReadableMap, promise: Promise) {
441
+ val path = params.getString("path")
442
+ if (path == null) {
443
+ promise.reject("ERROR", "path is required")
444
+ return
445
+ }
446
+ executor.execute {
447
+ try {
448
+ val result = standalonePrinter.removeFile(RemoveFileParams(path))
449
+ promise.resolve(Arguments.makeNativeMap(result.toMap()))
450
+ } catch (e: Exception) {
451
+ promise.reject("ERROR", e.message)
452
+ }
453
+ }
454
+ }
455
+
365
456
  override fun printText(params: ReadableMap, promise: Promise) {
366
457
  val text = params.getString("text")
367
458
  if (text == null) {
@@ -499,6 +590,7 @@ class ReactNativePrinterKitModule(reactContext: ReactApplicationContext) :
499
590
  service.printer.htmlToPdf(
500
591
  HtmlToPdfParams(
501
592
  html = html,
593
+ outputPath = params.optString("outputPath"),
502
594
  pageWidthDp = params.optInt("pageWidthDp", 412),
503
595
  heightDp = params.optIntOrNull("heightDp"),
504
596
  minPageHeightDp = params.optInt("minPageHeightDp", 1000)
@@ -10,6 +10,16 @@ import { TurboModuleRegistry, Platform } from 'react-native';
10
10
  * `null` means "unknown" - the printer did not answer or does not report that condition. It is NOT "ok".
11
11
  */
12
12
 
13
+ /**
14
+ * `PICTURES` is the public Pictures folder, so the image also shows in the Gallery app; it accepts images
15
+ * only (a `.png`/`.jpg` file name or an `image/...` `mimeType`) and refuses anything else.
16
+ */
17
+
18
+ /**
19
+ * The shape `readFile` returns the content in: `base64` (plain), `dataUri` (`data:<type>;base64,...`), `text`
20
+ * (decoded string), `hex` (two lower-case digits per byte) or `bytes` (array of numbers 0..255, max 1 MB).
21
+ */
22
+
13
23
  function getModule() {
14
24
  return Platform.OS === 'android' ? TurboModuleRegistry.getEnforcing('ReactNativePrinterKit') : {};
15
25
  }
@@ -1 +1 @@
1
- {"version":3,"names":["TurboModuleRegistry","Platform","getModule","OS","getEnforcing"],"sourceRoot":"../../src","sources":["NativeReactNativePrinterKit.ts"],"mappings":";;AAAA,SAASA,mBAAmB,EAAoBC,QAAQ,QAAQ,cAAc;;AAE9E;;AAGA;;AA2DA;AACA;AACA;;AA8PA,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":[]}
1
+ {"version":3,"names":["TurboModuleRegistry","Platform","getModule","OS","getEnforcing"],"sourceRoot":"../../src","sources":["NativeReactNativePrinterKit.ts"],"mappings":";;AAAA,SAASA,mBAAmB,EAAoBC,QAAQ,QAAQ,cAAc;;AAE9E;;AAGA;;AA2DA;AACA;AACA;;AAYA;AACA;AACA;AACA;;AA+HA;AACA;AACA;AACA;;AA2PA,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":[]}
@@ -31,6 +31,15 @@ export const FileLocation = {
31
31
  APP_FILES: 'APP_FILES',
32
32
  DOWNLOADS: 'DOWNLOADS',
33
33
  DOCUMENTS: 'DOCUMENTS',
34
+ PICTURES: 'PICTURES',
34
35
  CUSTOM_FOLDER: 'CUSTOM_FOLDER'
35
36
  };
37
+ /** The shape `readFile` returns the content in. */
38
+ export const ReadFileFormat = {
39
+ BASE64: 'base64',
40
+ DATA_URI: 'dataUri',
41
+ TEXT: 'text',
42
+ HEX: 'hex',
43
+ BYTES: 'bytes'
44
+ };
36
45
  //# sourceMappingURL=enums.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["PrinterConfidence","CONFIDENT","LIKELY","UNKNOWN","PrinterFilter","ALL","LIKELY_PRINTERS","STRICT","PrinterConnectionType","BLUETOOTH","NETWORK","USB","PrinterImageType","PNG","JPEG","FileLocation","CACHE","APP_FILES","DOWNLOADS","DOCUMENTS","CUSTOM_FOLDER"],"sourceRoot":"../../src","sources":["enums.ts"],"mappings":";;AAQA;AACA;AACA;AACA;;AAEA;AACA,OAAO,MAAMA,iBAAiB,GAAG;EAC/BC,SAAS,EAAE,WAAW;EACtBC,MAAM,EAAE,QAAQ;EAChBC,OAAO,EAAE;AACX,CAA2E;AAI3E;AACA,OAAO,MAAMC,aAAa,GAAG;EAC3BC,GAAG,EAAE,KAAK;EACVC,eAAe,EAAE,iBAAiB;EAClCC,MAAM,EAAE;AACV,CAAmE;AAGnE,OAAO,MAAMC,qBAAqB,GAAG;EACnCC,SAAS,EAAE,WAAW;EACtBC,OAAO,EAAE,SAAS;EAClBC,GAAG,EAAE;AACP,CAGC;AAID,OAAO,MAAMC,gBAAgB,GAAG;EAC9BC,GAAG,EAAE,KAAK;EACVC,IAAI,EAAE;AACR,CAAyE;AAIzE,OAAO,MAAMC,YAAY,GAAG;EAC1BC,KAAK,EAAE,OAAO;EACdC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,aAAa,EAAE;AACjB,CAAiE","ignoreList":[]}
1
+ {"version":3,"names":["PrinterConfidence","CONFIDENT","LIKELY","UNKNOWN","PrinterFilter","ALL","LIKELY_PRINTERS","STRICT","PrinterConnectionType","BLUETOOTH","NETWORK","USB","PrinterImageType","PNG","JPEG","FileLocation","CACHE","APP_FILES","DOWNLOADS","DOCUMENTS","PICTURES","CUSTOM_FOLDER","ReadFileFormat","BASE64","DATA_URI","TEXT","HEX","BYTES"],"sourceRoot":"../../src","sources":["enums.ts"],"mappings":";;AASA;AACA;AACA;AACA;;AAEA;AACA,OAAO,MAAMA,iBAAiB,GAAG;EAC/BC,SAAS,EAAE,WAAW;EACtBC,MAAM,EAAE,QAAQ;EAChBC,OAAO,EAAE;AACX,CAA2E;AAI3E;AACA,OAAO,MAAMC,aAAa,GAAG;EAC3BC,GAAG,EAAE,KAAK;EACVC,eAAe,EAAE,iBAAiB;EAClCC,MAAM,EAAE;AACV,CAAmE;AAGnE,OAAO,MAAMC,qBAAqB,GAAG;EACnCC,SAAS,EAAE,WAAW;EACtBC,OAAO,EAAE,SAAS;EAClBC,GAAG,EAAE;AACP,CAGC;AAID,OAAO,MAAMC,gBAAgB,GAAG;EAC9BC,GAAG,EAAE,KAAK;EACVC,IAAI,EAAE;AACR,CAAyE;AAIzE,OAAO,MAAMC,YAAY,GAAG;EAC1BC,KAAK,EAAE,OAAO;EACdC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,QAAQ,EAAE,UAAU;EACpBC,aAAa,EAAE;AACjB,CAAiE;AAGjE;AACA,OAAO,MAAMC,cAAc,GAAG;EAC5BC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE,SAAS;EACnBC,IAAI,EAAE,MAAM;EACZC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE;AACT,CAAwD","ignoreList":[]}
@@ -121,6 +121,44 @@ export function saveFile(params) {
121
121
  return ReactNativePrinterKit.saveFile(params);
122
122
  }
123
123
 
124
+ /**
125
+ * Reads ONE file and returns its content in the shape `format` asks for: `base64` (default), `dataUri`
126
+ * (`data:<type>;base64,...`), `text` (optionally with an `encoding`), `hex` or `bytes` (array of numbers,
127
+ * max 1 MB). `path` is an absolute path or the `content://` Uri `saveFile` returned. A file over `maxBytes`
128
+ * (default 10 MB) is refused instead of loaded. Never rejects: check `result.success`.
129
+ */
130
+ export function readFile(params) {
131
+ return ReactNativePrinterKit.readFile(params);
132
+ }
133
+
134
+ /**
135
+ * Renders HTML to ONE image file (PNG, or JPEG with `imageType: 'JPEG'`) and returns its path, or `null`
136
+ * on failure. Pass `outputPath` to choose the file name. A very tall page can run out of memory (then
137
+ * `null`). For base64 pass the returned path to `readFile`.
138
+ */
139
+ export function htmlToImage(params) {
140
+ return ReactNativePrinterKit.htmlToImage(params);
141
+ }
142
+
143
+ /**
144
+ * Reads ONE folder: the files and folders directly inside it, folders first and then A-Z (it does not
145
+ * go into sub-folders; call it again with an entry's `path` to go deeper). `result.names` is just the
146
+ * names, `result.entries` has `name`, `path`, `isDirectory`, `sizeBytes` and `lastModified`. A path that
147
+ * is a file, missing or relative is refused. Never rejects: check `result.success`.
148
+ */
149
+ export function readDir(params) {
150
+ return ReactNativePrinterKit.readDir(params);
151
+ }
152
+
153
+ /**
154
+ * Deletes ONE file: an absolute path, or the `content://` Uri `saveFile` returned. Never a folder or a
155
+ * pattern; cannot be undone. A missing file is a failure ("File not found"). Never rejects: check
156
+ * `result.success`.
157
+ */
158
+ export function removeFile(params) {
159
+ return ReactNativePrinterKit.removeFile(params);
160
+ }
161
+
124
162
  /**
125
163
  * Print raw text using the printer's built-in font (ASCII only - use
126
164
  * printHtml() for Bangla or other non-Latin scripts).
@@ -185,7 +223,7 @@ export function openFile(params) {
185
223
  }
186
224
 
187
225
  // Export enum-like constants (usable at runtime, and as types of the same name)
188
- export { FileLocation, PrinterConfidence, PrinterConnectionType, PrinterFilter, PrinterImageType } from "./enums.js";
226
+ export { FileLocation, PrinterConfidence, PrinterConnectionType, PrinterFilter, PrinterImageType, ReadFileFormat } from "./enums.js";
189
227
 
190
228
  // Export types
191
229
 
@@ -1 +1 @@
1
- {"version":3,"names":["ReactNativePrinterKit","isBluetoothEnabled","hasBluetoothPermission","requestBluetoothPermission","getBondedBluetoothPrinters","params","getUsbPrinters","hasUsbPermission","requestUsbPermission","connectPrinter","disconnectPrinter","isConnectedPrinter","getConnectedPrinter","isPrinterReady","getPrinterStatus","printTestPage","saveFile","printText","printImage","printImageBase64","pdfToImage","printPdf","htmlToPdf","printHtml","openFile","FileLocation","PrinterConfidence","PrinterConnectionType","PrinterFilter","PrinterImageType"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,qBAAqB,MAkBrB,kCAA+B;;AAEtC;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAA,EAAY;EAC5C,OAAOD,qBAAqB,CAACC,kBAAkB,CAAC,CAAC;AACnD;;AAEA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CAAA,EAAY;EAChD,OAAOF,qBAAqB,CAACE,sBAAsB,CAAC,CAAC;AACvD;;AAEA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CAAA,EAAqB;EAC7D,OAAOH,qBAAqB,CAACG,0BAA0B,CAAC,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CACxCC,MAA+B,GAAG,CAAC,CAAC,EACV;EAC1B,OAAOL,qBAAqB,CAACI,0BAA0B,CAACC,MAAM,CAAC;AACjE;;AAEA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAA,EAAuB;EACnD,OAAON,qBAAqB,CAACM,cAAc,CAAC,CAAC;AAC/C;;AAEA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACF,MAAuB,EAAW;EACjE,OAAOL,qBAAqB,CAACO,gBAAgB,CAACF,MAAM,CAAC;AACvD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,oBAAoBA,CAClCH,MAAuB,EACL;EAClB,OAAOL,qBAAqB,CAACQ,oBAAoB,CAACH,MAAM,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,cAAcA,CAACJ,MAA4B,EAAoB;EAC7E,OAAOL,qBAAqB,CAACS,cAAc,CAACJ,MAAM,CAAC;AACrD;;AAEA;AACA;AACA;AACA,OAAO,SAASK,iBAAiBA,CAA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pE,OAAOL,qBAAqB,CAACoB,UAAU,CAACf,MAAM,CAAC;AACjD;;AAEA;AACA;AACA;AACA,OAAO,SAASgB,QAAQA,CAAChB,MAAsB,EAAiB;EAC9D,OAAOL,qBAAqB,CAACqB,QAAQ,CAAChB,MAAM,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASiB,SAASA,CAACjB,MAAuB,EAA0B;EACzE,OAAOL,qBAAqB,CAACsB,SAAS,CAACjB,MAAM,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASkB,SAASA,CAAClB,MAAuB,EAAoB;EACnE,OAAOL,qBAAqB,CAACuB,SAAS,CAAClB,MAAM,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASmB,QAAQA,CAACnB,MAAsB,EAAW;EACxD,OAAOL,qBAAqB,CAACwB,QAAQ,CAACnB,MAAM,CAAC;AAC/C;;AAEA;AACA,SACEoB,YAAY,EACZC,iBAAiB,EACjBC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,QACX,YAAS;;AAEhB;;AAqBA;AACA,eAAe7B,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["ReactNativePrinterKit","isBluetoothEnabled","hasBluetoothPermission","requestBluetoothPermission","getBondedBluetoothPrinters","params","getUsbPrinters","hasUsbPermission","requestUsbPermission","connectPrinter","disconnectPrinter","isConnectedPrinter","getConnectedPrinter","isPrinterReady","getPrinterStatus","printTestPage","saveFile","readFile","htmlToImage","readDir","removeFile","printText","printImage","printImageBase64","pdfToImage","printPdf","htmlToPdf","printHtml","openFile","FileLocation","PrinterConfidence","PrinterConnectionType","PrinterFilter","PrinterImageType","ReadFileFormat"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,qBAAqB,MA0BrB,kCAA+B;;AAEtC;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAA,EAAY;EAC5C,OAAOD,qBAAqB,CAACC,kBAAk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EAAiB;EAClE,OAAOL,qBAAqB,CAACsB,UAAU,CAACjB,MAAM,CAAC;AACjD;;AAEA;AACA;AACA;AACA,OAAO,SAASkB,gBAAgBA,CAC9BlB,MAA8B,EACf;EACf,OAAOL,qBAAqB,CAACuB,gBAAgB,CAAClB,MAAM,CAAC;AACvD;;AAEA;AACA;AACA;AACA,OAAO,SAASmB,UAAUA,CAACnB,MAAwB,EAAmB;EACpE,OAAOL,qBAAqB,CAACwB,UAAU,CAACnB,MAAM,CAAC;AACjD;;AAEA;AACA;AACA;AACA,OAAO,SAASoB,QAAQA,CAACpB,MAAsB,EAAiB;EAC9D,OAAOL,qBAAqB,CAACyB,QAAQ,CAACpB,MAAM,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASqB,SAASA,CAACrB,MAAuB,EAA0B;EACzE,OAAOL,qBAAqB,CAAC0B,SAAS,CAACrB,MAAM,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASsB,SAASA,CAACtB,MAAuB,EAAoB;EACnE,OAAOL,qBAAqB,CAAC2B,SAAS,CAACtB,MAAM,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASuB,QAAQA,CAACvB,MAAsB,EAAW;EACxD,OAAOL,qBAAqB,CAAC4B,QAAQ,CAACvB,MAAM,CAAC;AAC/C;;AAEA;AACA,SACEwB,YAAY,EACZC,iBAAiB,EACjBC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,cAAc,QACT,YAAS;;AAEhB;;AA6BA;AACA,eAAelC,qBAAqB","ignoreList":[]}
@@ -64,10 +64,22 @@ export type PrinterStatus = {
64
64
  coverOpen: boolean | null;
65
65
  hasError: boolean | null;
66
66
  };
67
- export type FileLocation = 'CACHE' | 'APP_FILES' | 'DOWNLOADS' | 'DOCUMENTS' | 'CUSTOM_FOLDER';
67
+ /**
68
+ * `PICTURES` is the public Pictures folder, so the image also shows in the Gallery app; it accepts images
69
+ * only (a `.png`/`.jpg` file name or an `image/...` `mimeType`) and refuses anything else.
70
+ */
71
+ export type FileLocation = 'CACHE' | 'APP_FILES' | 'DOWNLOADS' | 'DOCUMENTS' | 'PICTURES' | 'CUSTOM_FOLDER';
68
72
  export type SaveFileParams = {
69
- sourcePath: string;
70
- /** Defaults to the source file's name. */
73
+ /** Path of an existing file to copy. Give exactly one of `sourcePath`, `text` or `base64`. */
74
+ sourcePath?: string;
75
+ /** Content to save as UTF-8 text, instead of `sourcePath`. Needs `fileName`. */
76
+ text?: string;
77
+ /**
78
+ * Content to save as bytes (base64 encoded; a `data:...;base64,` prefix is fine), instead of
79
+ * `sourcePath`. Needs `fileName`. Use it for images, PDFs and other binary data.
80
+ */
81
+ base64?: string;
82
+ /** Defaults to the source file's name. Required with `text` or `base64`. */
71
83
  fileName?: string;
72
84
  /** Default `DOWNLOADS`. */
73
85
  location?: FileLocation;
@@ -126,6 +138,15 @@ export type PrintPdfParams = {
126
138
  };
127
139
  export type HtmlToPdfParams = {
128
140
  html: string;
141
+ /**
142
+ * Full path of the PDF to write, file name included (e.g.
143
+ * `/data/user/0/<your.app>/files/invoice.pdf`). Leave it out to get a fresh file with a
144
+ * generated name in the app's cache folder. The folder must already exist and be one the
145
+ * app may write to (its own files/cache folders); an existing file is overwritten. To put
146
+ * the PDF in a public folder such as Downloads, convert first and then call `saveFile`.
147
+ * The path that was written is returned.
148
+ */
149
+ outputPath?: string;
129
150
  pageWidthDp?: number;
130
151
  heightDp?: number;
131
152
  minPageHeightDp?: number;
@@ -141,6 +162,84 @@ export type PrintHtmlParams = {
141
162
  /** See PrintImageParams.bandDelayMs. */
142
163
  bandDelayMs?: number;
143
164
  };
165
+ export type RemoveFileParams = {
166
+ /**
167
+ * What to delete: an absolute file path, or the `content://` Uri that `saveFile` returned (for
168
+ * a file in Downloads/Documents on Android 10+, which only works for files your app created).
169
+ */
170
+ path: string;
171
+ };
172
+ export type RemoveFileResult = {
173
+ success: boolean;
174
+ path: string | null;
175
+ uri: string | null;
176
+ fileName: string | null;
177
+ error: string | null;
178
+ };
179
+ /**
180
+ * The shape `readFile` returns the content in: `base64` (plain), `dataUri` (`data:<type>;base64,...`), `text`
181
+ * (decoded string), `hex` (two lower-case digits per byte) or `bytes` (array of numbers 0..255, max 1 MB).
182
+ */
183
+ export type ReadFileFormat = 'base64' | 'dataUri' | 'text' | 'hex' | 'bytes';
184
+ export type ReadFileParams = {
185
+ /** An absolute file path, or the `content://` Uri that `saveFile` returned. */
186
+ path: string;
187
+ /** Default `base64`. */
188
+ format?: ReadFileFormat;
189
+ /** Only for `text`: `UTF-8` (default), `UTF-16`, `ISO-8859-1`, ... */
190
+ encoding?: string;
191
+ /** Files bigger than this are refused instead of loaded. Default 10 MB; `bytes` is always capped at 1 MB. */
192
+ maxBytes?: number;
193
+ };
194
+ export type ReadFileResult = {
195
+ success: boolean;
196
+ format: ReadFileFormat | null;
197
+ /** Set for `base64`, `dataUri`, `text` and `hex`. */
198
+ content: string | null;
199
+ /** Set for `bytes`. */
200
+ bytes: number[] | null;
201
+ sizeBytes: number | null;
202
+ /** From the file extension, or the content provider's answer for a Uri. */
203
+ mimeType: string | null;
204
+ error: string | null;
205
+ };
206
+ export type HtmlToImageParams = {
207
+ html: string;
208
+ /** Full path of the image to write, file name included (folder must exist). Default: generated name in the cache folder. */
209
+ outputPath?: string;
210
+ /** Default `PNG`. */
211
+ imageType?: PrinterImageType;
212
+ /** Width of the image in pixels. Default: twice the page width. */
213
+ targetWidthPx?: number;
214
+ pageWidthDp?: number;
215
+ heightDp?: number;
216
+ minPageHeightDp?: number;
217
+ };
218
+ export type ReadDirParams = {
219
+ /**
220
+ * The folder to read: an absolute folder path, or a `content://` Uri of a folder the user picked
221
+ * with the system folder picker (or the `path` of a sub-folder returned by an earlier call).
222
+ */
223
+ path: string;
224
+ };
225
+ export type DirEntry = {
226
+ name: string;
227
+ /** Pass it to `removeFile` (a file) or to `readDir` again (a folder). */
228
+ path: string;
229
+ isDirectory: boolean;
230
+ /** `null` for a folder. */
231
+ sizeBytes: number | null;
232
+ /** Milliseconds since 1970, `null` if unknown. */
233
+ lastModified: number | null;
234
+ };
235
+ export type ReadDirResult = {
236
+ success: boolean;
237
+ path: string | null;
238
+ /** Just the names, in the same order as `entries`. */
239
+ names: string[];
240
+ entries: DirEntry[];
241
+ error: string | null;
242
+ };
144
243
  export type OpenFileParams = {
145
244
  path: string;
146
245
  /** Inferred from the file extension if not given. */
@@ -216,8 +315,9 @@ export interface Spec extends TurboModule {
216
315
  */
217
316
  printTestPage(): Promise<void>;
218
317
  /**
219
- * Copies a finished file (e.g. the PDF from `htmlToPdf`) to cache, app storage, public
220
- * Downloads/Documents or a chosen folder. Never rejects: check `result.success`.
318
+ * Saves a file to cache, app storage, public Downloads/Documents or a chosen folder: either
319
+ * copies an existing file (`sourcePath`, e.g. the PDF from `htmlToPdf`) or writes content you
320
+ * pass directly (`text` or `base64`, with a `fileName`). Never rejects: check `result.success`.
221
321
  */
222
322
  saveFile(params: SaveFileParams): Promise<SaveFileResult>;
223
323
  /**
@@ -261,6 +361,30 @@ export interface Spec extends TurboModule {
261
361
  * content with Bangla or other non-Latin text, or any real HTML/CSS layout.
262
362
  */
263
363
  printHtml(params: PrintHtmlParams): Promise<boolean>;
364
+ /**
365
+ * Deletes ONE file (what `saveFile` wrote, or any file your app may delete). Never a folder, never a
366
+ * pattern; cannot be undone. A missing file is reported as a failure ("File not found").
367
+ * Never rejects: check `result.success`.
368
+ */
369
+ removeFile(params: RemoveFileParams): Promise<RemoveFileResult>;
370
+ /**
371
+ * Reads ONE file and returns its content in the shape `format` asks for (`base64`, `dataUri`, `text`,
372
+ * `hex` or `bytes`). Read-only. A file over `maxBytes` (default 10 MB) is refused instead of loaded.
373
+ * Never rejects: check `result.success`.
374
+ */
375
+ readFile(params: ReadFileParams): Promise<ReadFileResult>;
376
+ /**
377
+ * Renders HTML to ONE image file (PNG or JPEG) and returns its absolute path, or `null` on failure.
378
+ * It is `htmlToPdf` plus one rendered page, so a very tall page makes a very large bitmap and can run
379
+ * out of memory (then the result is `null`). For base64 pass the path to `readFile`.
380
+ */
381
+ htmlToImage(params: HtmlToImageParams): Promise<string | null>;
382
+ /**
383
+ * Reads ONE folder: the files and folders directly inside it (not their contents), folders first and
384
+ * then A-Z. Read-only. A path that is a file, missing or relative is refused. Never rejects: check
385
+ * `result.success`.
386
+ */
387
+ readDir(params: ReadDirParams): Promise<ReadDirResult>;
264
388
  /**
265
389
  * Opens a file with whatever app the user has installed that can handle its
266
390
  * type (e.g. a PDF viewer) - shows the system's "Open with" chooser if more
@@ -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,2EAA2E;AAC3E,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEnE,+GAA+G;AAC/G,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,iBAAiB,GAAG,QAAQ,CAAC;AAEjE,MAAM,MAAM,qBAAqB,GAAG,WAAW,GAAG,SAAS,GAAG,KAAK,CAAC;AAEpE,MAAM,MAAM,sBAAsB,GAAG;IACnC,sCAAsC;IACtC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,oGAAoG;IACpG,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,yFAAyF;IACzF,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,kFAAkF;IAClF,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAA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AAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE3D;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAErD;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAEhE;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE1D;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE/D;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAEvD;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC;CAC3C;;AAQD,wBAA2B"}
@@ -28,7 +28,17 @@ export declare const FileLocation: {
28
28
  readonly APP_FILES: "APP_FILES";
29
29
  readonly DOWNLOADS: "DOWNLOADS";
30
30
  readonly DOCUMENTS: "DOCUMENTS";
31
+ readonly PICTURES: "PICTURES";
31
32
  readonly CUSTOM_FOLDER: "CUSTOM_FOLDER";
32
33
  };
33
34
  export type FileLocation = (typeof FileLocation)[keyof typeof FileLocation];
35
+ /** The shape `readFile` returns the content in. */
36
+ export declare const ReadFileFormat: {
37
+ readonly BASE64: "base64";
38
+ readonly DATA_URI: "dataUri";
39
+ readonly TEXT: "text";
40
+ readonly HEX: "hex";
41
+ readonly BYTES: "bytes";
42
+ };
43
+ export type ReadFileFormat = (typeof ReadFileFormat)[keyof typeof ReadFileFormat];
34
44
  //# sourceMappingURL=enums.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enums.d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AC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE,eAAO,MAAM,gBAAgB;;;CAG4C,CAAC;AAC1E,MAAM,MAAM,gBAAgB,GAC1B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D,eAAO,MAAM,YAAY;;;;;;;CAOwC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE5E,mDAAmD;AACnD,eAAO,MAAM,cAAc;;;;;;CAM6B,CAAC;AACzD,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import ReactNativePrinterKit, { type BluetoothPrinterDevice, type ConnectPrinterParams, type GetBondedPrintersParams, type HtmlToPdfParams, type OpenFileParams, type PdfToImageParams, type PrinterStatus, type PrinterStatusParams, type PrintHtmlParams, type PrintImageBase64Params, type PrintImageParams, type PrintPdfParams, type PrintTextParams, type SaveFileParams, type SaveFileResult, type UsbDeviceParams, type UsbPrinterDevice } from './NativeReactNativePrinterKit.js';
1
+ import ReactNativePrinterKit, { type BluetoothPrinterDevice, type ConnectPrinterParams, type DirEntry, type HtmlToImageParams, type GetBondedPrintersParams, type HtmlToPdfParams, type OpenFileParams, type PdfToImageParams, type PrinterStatus, type PrinterStatusParams, type PrintHtmlParams, type PrintImageBase64Params, type PrintImageParams, type PrintPdfParams, type PrintTextParams, type ReadDirParams, type ReadDirResult, type ReadFileParams, type ReadFileResult, type RemoveFileParams, type RemoveFileResult, type SaveFileParams, type SaveFileResult, type UsbDeviceParams, type UsbPrinterDevice } from './NativeReactNativePrinterKit.js';
2
2
  /**
3
3
  * Whether the device's Bluetooth adapter itself is turned on. Needs no runtime
4
4
  * permission - check this before `hasBluetoothPermission`/`requestBluetoothPermission`.
@@ -73,6 +73,32 @@ export declare function printTestPage(): Promise<void>;
73
73
  * Downloads/Documents or a chosen folder. Never rejects: check `result.success`.
74
74
  */
75
75
  export declare function saveFile(params: SaveFileParams): Promise<SaveFileResult>;
76
+ /**
77
+ * Reads ONE file and returns its content in the shape `format` asks for: `base64` (default), `dataUri`
78
+ * (`data:<type>;base64,...`), `text` (optionally with an `encoding`), `hex` or `bytes` (array of numbers,
79
+ * max 1 MB). `path` is an absolute path or the `content://` Uri `saveFile` returned. A file over `maxBytes`
80
+ * (default 10 MB) is refused instead of loaded. Never rejects: check `result.success`.
81
+ */
82
+ export declare function readFile(params: ReadFileParams): Promise<ReadFileResult>;
83
+ /**
84
+ * Renders HTML to ONE image file (PNG, or JPEG with `imageType: 'JPEG'`) and returns its path, or `null`
85
+ * on failure. Pass `outputPath` to choose the file name. A very tall page can run out of memory (then
86
+ * `null`). For base64 pass the returned path to `readFile`.
87
+ */
88
+ export declare function htmlToImage(params: HtmlToImageParams): Promise<string | null>;
89
+ /**
90
+ * Reads ONE folder: the files and folders directly inside it, folders first and then A-Z (it does not
91
+ * go into sub-folders; call it again with an entry's `path` to go deeper). `result.names` is just the
92
+ * names, `result.entries` has `name`, `path`, `isDirectory`, `sizeBytes` and `lastModified`. A path that
93
+ * is a file, missing or relative is refused. Never rejects: check `result.success`.
94
+ */
95
+ export declare function readDir(params: ReadDirParams): Promise<ReadDirResult>;
96
+ /**
97
+ * Deletes ONE file: an absolute path, or the `content://` Uri `saveFile` returned. Never a folder or a
98
+ * pattern; cannot be undone. A missing file is a failure ("File not found"). Never rejects: check
99
+ * `result.success`.
100
+ */
101
+ export declare function removeFile(params: RemoveFileParams): Promise<RemoveFileResult>;
76
102
  /**
77
103
  * Print raw text using the printer's built-in font (ASCII only - use
78
104
  * printHtml() for Bangla or other non-Latin scripts).
@@ -112,7 +138,7 @@ export declare function printHtml(params: PrintHtmlParams): Promise<boolean>;
112
138
  * can open it.
113
139
  */
114
140
  export declare function openFile(params: OpenFileParams): boolean;
115
- export { FileLocation, PrinterConfidence, PrinterConnectionType, PrinterFilter, PrinterImageType, } from './enums.js';
116
- export type { BluetoothPrinterDevice, ConnectPrinterParams, GetBondedPrintersParams, HtmlToPdfParams, OpenFileParams, PdfToImageParams, PrinterStatus, PrinterStatusParams, PrintHtmlParams, PrintImageBase64Params, PrintImageParams, PrintPdfParams, PrintTextParams, SaveFileParams, SaveFileResult, UsbDeviceParams, UsbPrinterDevice, };
141
+ export { FileLocation, PrinterConfidence, PrinterConnectionType, PrinterFilter, PrinterImageType, ReadFileFormat, } from './enums.js';
142
+ export type { BluetoothPrinterDevice, ConnectPrinterParams, DirEntry, GetBondedPrintersParams, HtmlToImageParams, HtmlToPdfParams, OpenFileParams, PdfToImageParams, PrinterStatus, PrinterStatusParams, PrintHtmlParams, PrintImageBase64Params, PrintImageParams, PrintPdfParams, PrintTextParams, ReadDirParams, ReadDirResult, ReadFileParams, ReadFileResult, RemoveFileParams, RemoveFileResult, SaveFileParams, SaveFileResult, UsbDeviceParams, UsbPrinterDevice, };
117
143
  export default ReactNativePrinterKit;
118
144
  //# 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,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,kCAA+B,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAED;;GAEG;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,CAAC,MAAM,GAAG,IAAI,CAAC,CAEzE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAExD;AAGD,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,YAAS,CAAC;AAGjB,YAAY,EACV,sBAAsB,EACtB,oBAAoB,EACpB,QAAQ,EACR,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,aAAa,EACb,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,GACjB,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.4.0",
3
+ "version": "0.4.1",
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",
@@ -76,12 +76,29 @@ export type PrinterStatus = {
76
76
  hasError: boolean | null;
77
77
  };
78
78
 
79
+ /**
80
+ * `PICTURES` is the public Pictures folder, so the image also shows in the Gallery app; it accepts images
81
+ * only (a `.png`/`.jpg` file name or an `image/...` `mimeType`) and refuses anything else.
82
+ */
79
83
  export type FileLocation =
80
- 'CACHE' | 'APP_FILES' | 'DOWNLOADS' | 'DOCUMENTS' | 'CUSTOM_FOLDER';
84
+ | 'CACHE'
85
+ | 'APP_FILES'
86
+ | 'DOWNLOADS'
87
+ | 'DOCUMENTS'
88
+ | 'PICTURES'
89
+ | 'CUSTOM_FOLDER';
81
90
 
82
91
  export type SaveFileParams = {
83
- sourcePath: string;
84
- /** Defaults to the source file's name. */
92
+ /** Path of an existing file to copy. Give exactly one of `sourcePath`, `text` or `base64`. */
93
+ sourcePath?: string;
94
+ /** Content to save as UTF-8 text, instead of `sourcePath`. Needs `fileName`. */
95
+ text?: string;
96
+ /**
97
+ * Content to save as bytes (base64 encoded; a `data:...;base64,` prefix is fine), instead of
98
+ * `sourcePath`. Needs `fileName`. Use it for images, PDFs and other binary data.
99
+ */
100
+ base64?: string;
101
+ /** Defaults to the source file's name. Required with `text` or `base64`. */
85
102
  fileName?: string;
86
103
  /** Default `DOWNLOADS`. */
87
104
  location?: FileLocation;
@@ -147,6 +164,15 @@ export type PrintPdfParams = {
147
164
 
148
165
  export type HtmlToPdfParams = {
149
166
  html: string;
167
+ /**
168
+ * Full path of the PDF to write, file name included (e.g.
169
+ * `/data/user/0/<your.app>/files/invoice.pdf`). Leave it out to get a fresh file with a
170
+ * generated name in the app's cache folder. The folder must already exist and be one the
171
+ * app may write to (its own files/cache folders); an existing file is overwritten. To put
172
+ * the PDF in a public folder such as Downloads, convert first and then call `saveFile`.
173
+ * The path that was written is returned.
174
+ */
175
+ outputPath?: string;
150
176
  pageWidthDp?: number;
151
177
  heightDp?: number;
152
178
  minPageHeightDp?: number;
@@ -164,6 +190,93 @@ export type PrintHtmlParams = {
164
190
  bandDelayMs?: number;
165
191
  };
166
192
 
193
+ export type RemoveFileParams = {
194
+ /**
195
+ * What to delete: an absolute file path, or the `content://` Uri that `saveFile` returned (for
196
+ * a file in Downloads/Documents on Android 10+, which only works for files your app created).
197
+ */
198
+ path: string;
199
+ };
200
+
201
+ export type RemoveFileResult = {
202
+ success: boolean;
203
+ path: string | null;
204
+ uri: string | null;
205
+ fileName: string | null;
206
+ error: string | null;
207
+ };
208
+
209
+ /**
210
+ * The shape `readFile` returns the content in: `base64` (plain), `dataUri` (`data:<type>;base64,...`), `text`
211
+ * (decoded string), `hex` (two lower-case digits per byte) or `bytes` (array of numbers 0..255, max 1 MB).
212
+ */
213
+ export type ReadFileFormat = 'base64' | 'dataUri' | 'text' | 'hex' | 'bytes';
214
+
215
+ export type ReadFileParams = {
216
+ /** An absolute file path, or the `content://` Uri that `saveFile` returned. */
217
+ path: string;
218
+ /** Default `base64`. */
219
+ format?: ReadFileFormat;
220
+ /** Only for `text`: `UTF-8` (default), `UTF-16`, `ISO-8859-1`, ... */
221
+ encoding?: string;
222
+ /** Files bigger than this are refused instead of loaded. Default 10 MB; `bytes` is always capped at 1 MB. */
223
+ maxBytes?: number;
224
+ };
225
+
226
+ export type ReadFileResult = {
227
+ success: boolean;
228
+ format: ReadFileFormat | null;
229
+ /** Set for `base64`, `dataUri`, `text` and `hex`. */
230
+ content: string | null;
231
+ /** Set for `bytes`. */
232
+ bytes: number[] | null;
233
+ sizeBytes: number | null;
234
+ /** From the file extension, or the content provider's answer for a Uri. */
235
+ mimeType: string | null;
236
+ error: string | null;
237
+ };
238
+
239
+ export type HtmlToImageParams = {
240
+ html: string;
241
+ /** Full path of the image to write, file name included (folder must exist). Default: generated name in the cache folder. */
242
+ outputPath?: string;
243
+ /** Default `PNG`. */
244
+ imageType?: PrinterImageType;
245
+ /** Width of the image in pixels. Default: twice the page width. */
246
+ targetWidthPx?: number;
247
+ pageWidthDp?: number;
248
+ heightDp?: number;
249
+ minPageHeightDp?: number;
250
+ };
251
+
252
+ export type ReadDirParams = {
253
+ /**
254
+ * The folder to read: an absolute folder path, or a `content://` Uri of a folder the user picked
255
+ * with the system folder picker (or the `path` of a sub-folder returned by an earlier call).
256
+ */
257
+ path: string;
258
+ };
259
+
260
+ export type DirEntry = {
261
+ name: string;
262
+ /** Pass it to `removeFile` (a file) or to `readDir` again (a folder). */
263
+ path: string;
264
+ isDirectory: boolean;
265
+ /** `null` for a folder. */
266
+ sizeBytes: number | null;
267
+ /** Milliseconds since 1970, `null` if unknown. */
268
+ lastModified: number | null;
269
+ };
270
+
271
+ export type ReadDirResult = {
272
+ success: boolean;
273
+ path: string | null;
274
+ /** Just the names, in the same order as `entries`. */
275
+ names: string[];
276
+ entries: DirEntry[];
277
+ error: string | null;
278
+ };
279
+
167
280
  export type OpenFileParams = {
168
281
  path: string;
169
282
  /** Inferred from the file extension if not given. */
@@ -256,8 +369,9 @@ export interface Spec extends TurboModule {
256
369
  printTestPage(): Promise<void>;
257
370
 
258
371
  /**
259
- * Copies a finished file (e.g. the PDF from `htmlToPdf`) to cache, app storage, public
260
- * Downloads/Documents or a chosen folder. Never rejects: check `result.success`.
372
+ * Saves a file to cache, app storage, public Downloads/Documents or a chosen folder: either
373
+ * copies an existing file (`sourcePath`, e.g. the PDF from `htmlToPdf`) or writes content you
374
+ * pass directly (`text` or `base64`, with a `fileName`). Never rejects: check `result.success`.
261
375
  */
262
376
  saveFile(params: SaveFileParams): Promise<SaveFileResult>;
263
377
 
@@ -309,6 +423,34 @@ export interface Spec extends TurboModule {
309
423
  */
310
424
  printHtml(params: PrintHtmlParams): Promise<boolean>;
311
425
 
426
+ /**
427
+ * Deletes ONE file (what `saveFile` wrote, or any file your app may delete). Never a folder, never a
428
+ * pattern; cannot be undone. A missing file is reported as a failure ("File not found").
429
+ * Never rejects: check `result.success`.
430
+ */
431
+ removeFile(params: RemoveFileParams): Promise<RemoveFileResult>;
432
+
433
+ /**
434
+ * Reads ONE file and returns its content in the shape `format` asks for (`base64`, `dataUri`, `text`,
435
+ * `hex` or `bytes`). Read-only. A file over `maxBytes` (default 10 MB) is refused instead of loaded.
436
+ * Never rejects: check `result.success`.
437
+ */
438
+ readFile(params: ReadFileParams): Promise<ReadFileResult>;
439
+
440
+ /**
441
+ * Renders HTML to ONE image file (PNG or JPEG) and returns its absolute path, or `null` on failure.
442
+ * It is `htmlToPdf` plus one rendered page, so a very tall page makes a very large bitmap and can run
443
+ * out of memory (then the result is `null`). For base64 pass the path to `readFile`.
444
+ */
445
+ htmlToImage(params: HtmlToImageParams): Promise<string | null>;
446
+
447
+ /**
448
+ * Reads ONE folder: the files and folders directly inside it (not their contents), folders first and
449
+ * then A-Z. Read-only. A path that is a file, missing or relative is refused. Never rejects: check
450
+ * `result.success`.
451
+ */
452
+ readDir(params: ReadDirParams): Promise<ReadDirResult>;
453
+
312
454
  /**
313
455
  * Opens a file with whatever app the user has installed that can handle its
314
456
  * type (e.g. a PDF viewer) - shows the system's "Open with" chooser if more
package/src/enums.ts CHANGED
@@ -4,6 +4,7 @@ import type {
4
4
  PrinterConnectionType as PrinterConnectionTypeValue,
5
5
  PrinterFilter as PrinterFilterValue,
6
6
  PrinterImageType as PrinterImageTypeValue,
7
+ ReadFileFormat as ReadFileFormatValue,
7
8
  } from './NativeReactNativePrinterKit';
8
9
 
9
10
  // Runtime values for the string unions the native module uses, so callers can write
@@ -51,6 +52,18 @@ export const FileLocation = {
51
52
  APP_FILES: 'APP_FILES',
52
53
  DOWNLOADS: 'DOWNLOADS',
53
54
  DOCUMENTS: 'DOCUMENTS',
55
+ PICTURES: 'PICTURES',
54
56
  CUSTOM_FOLDER: 'CUSTOM_FOLDER',
55
57
  } as const satisfies Record<FileLocationValue, FileLocationValue>;
56
58
  export type FileLocation = (typeof FileLocation)[keyof typeof FileLocation];
59
+
60
+ /** The shape `readFile` returns the content in. */
61
+ export const ReadFileFormat = {
62
+ BASE64: 'base64',
63
+ DATA_URI: 'dataUri',
64
+ TEXT: 'text',
65
+ HEX: 'hex',
66
+ BYTES: 'bytes',
67
+ } as const satisfies Record<string, ReadFileFormatValue>;
68
+ export type ReadFileFormat =
69
+ (typeof ReadFileFormat)[keyof typeof ReadFileFormat];
package/src/index.tsx CHANGED
@@ -1,6 +1,8 @@
1
1
  import ReactNativePrinterKit, {
2
2
  type BluetoothPrinterDevice,
3
3
  type ConnectPrinterParams,
4
+ type DirEntry,
5
+ type HtmlToImageParams,
4
6
  type GetBondedPrintersParams,
5
7
  type HtmlToPdfParams,
6
8
  type OpenFileParams,
@@ -12,6 +14,12 @@ import ReactNativePrinterKit, {
12
14
  type PrintImageParams,
13
15
  type PrintPdfParams,
14
16
  type PrintTextParams,
17
+ type ReadDirParams,
18
+ type ReadDirResult,
19
+ type ReadFileParams,
20
+ type ReadFileResult,
21
+ type RemoveFileParams,
22
+ type RemoveFileResult,
15
23
  type SaveFileParams,
16
24
  type SaveFileResult,
17
25
  type UsbDeviceParams,
@@ -143,6 +151,46 @@ export function saveFile(params: SaveFileParams): Promise<SaveFileResult> {
143
151
  return ReactNativePrinterKit.saveFile(params);
144
152
  }
145
153
 
154
+ /**
155
+ * Reads ONE file and returns its content in the shape `format` asks for: `base64` (default), `dataUri`
156
+ * (`data:<type>;base64,...`), `text` (optionally with an `encoding`), `hex` or `bytes` (array of numbers,
157
+ * max 1 MB). `path` is an absolute path or the `content://` Uri `saveFile` returned. A file over `maxBytes`
158
+ * (default 10 MB) is refused instead of loaded. Never rejects: check `result.success`.
159
+ */
160
+ export function readFile(params: ReadFileParams): Promise<ReadFileResult> {
161
+ return ReactNativePrinterKit.readFile(params);
162
+ }
163
+
164
+ /**
165
+ * Renders HTML to ONE image file (PNG, or JPEG with `imageType: 'JPEG'`) and returns its path, or `null`
166
+ * on failure. Pass `outputPath` to choose the file name. A very tall page can run out of memory (then
167
+ * `null`). For base64 pass the returned path to `readFile`.
168
+ */
169
+ export function htmlToImage(params: HtmlToImageParams): Promise<string | null> {
170
+ return ReactNativePrinterKit.htmlToImage(params);
171
+ }
172
+
173
+ /**
174
+ * Reads ONE folder: the files and folders directly inside it, folders first and then A-Z (it does not
175
+ * go into sub-folders; call it again with an entry's `path` to go deeper). `result.names` is just the
176
+ * names, `result.entries` has `name`, `path`, `isDirectory`, `sizeBytes` and `lastModified`. A path that
177
+ * is a file, missing or relative is refused. Never rejects: check `result.success`.
178
+ */
179
+ export function readDir(params: ReadDirParams): Promise<ReadDirResult> {
180
+ return ReactNativePrinterKit.readDir(params);
181
+ }
182
+
183
+ /**
184
+ * Deletes ONE file: an absolute path, or the `content://` Uri `saveFile` returned. Never a folder or a
185
+ * pattern; cannot be undone. A missing file is a failure ("File not found"). Never rejects: check
186
+ * `result.success`.
187
+ */
188
+ export function removeFile(
189
+ params: RemoveFileParams
190
+ ): Promise<RemoveFileResult> {
191
+ return ReactNativePrinterKit.removeFile(params);
192
+ }
193
+
146
194
  /**
147
195
  * Print raw text using the printer's built-in font (ASCII only - use
148
196
  * printHtml() for Bangla or other non-Latin scripts).
@@ -215,13 +263,16 @@ export {
215
263
  PrinterConnectionType,
216
264
  PrinterFilter,
217
265
  PrinterImageType,
266
+ ReadFileFormat,
218
267
  } from './enums';
219
268
 
220
269
  // Export types
221
270
  export type {
222
271
  BluetoothPrinterDevice,
223
272
  ConnectPrinterParams,
273
+ DirEntry,
224
274
  GetBondedPrintersParams,
275
+ HtmlToImageParams,
225
276
  HtmlToPdfParams,
226
277
  OpenFileParams,
227
278
  PdfToImageParams,
@@ -232,6 +283,12 @@ export type {
232
283
  PrintImageParams,
233
284
  PrintPdfParams,
234
285
  PrintTextParams,
286
+ ReadDirParams,
287
+ ReadDirResult,
288
+ ReadFileParams,
289
+ ReadFileResult,
290
+ RemoveFileParams,
291
+ RemoveFileResult,
235
292
  SaveFileParams,
236
293
  SaveFileResult,
237
294
  UsbDeviceParams,