@qrcommunication/gigapdf-lib 0.53.0 → 0.55.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/dist/index.d.cts CHANGED
@@ -21,12 +21,19 @@ type Exports = {
21
21
  /**
22
22
  * A trained per-script OCR model bundled with the package. `alpha` covers
23
23
  * Latin, Cyrillic and Greek; `arabic` is the **RTL group** (Arabic, Urdu,
24
- * Hebrew); the rest are dedicated scripts. The matching `.gpocr` CRNN blob
25
- * ships under `models/` and is host-loaded on demand. To recognize any shipped
26
- * language at once (including models added later), prefer
24
+ * Hebrew); `cjk` is Chinese (2401-class); `japanese` / `korean` are their own
25
+ * groups (kana+kanji / Hangul, each + full ASCII for mixed alphanumerics); the
26
+ * rest are dedicated Indic scripts. The matching `.gpocr` CRNN blob ships under
27
+ * `models/` and is host-loaded on demand. To recognize any shipped language at
28
+ * once (including models added later), prefer
27
29
  * {@link GigaPdfEngine.loadAllBundledOcrModels}.
30
+ *
31
+ * Some models may not be bundled in every release (a script can still be
32
+ * training upstream) — {@link GigaPdfEngine.loadBundledOcrModel} returns `false`
33
+ * for an absent blob instead of throwing, so listing them in
34
+ * {@link ALL_OCR_SCRIPTS} stays safe.
28
35
  */
29
- type OcrScript = "alpha" | "arabic" | "devanagari" | "bengali" | "tamil";
36
+ type OcrScript = "alpha" | "arabic" | "devanagari" | "bengali" | "tamil" | "cjk" | "japanese" | "korean";
30
37
  /** Every trained script — load all for "recognize text in any language". */
31
38
  declare const ALL_OCR_SCRIPTS: readonly OcrScript[];
32
39
  /** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
@@ -97,6 +104,23 @@ declare class GigaPdfEngine {
97
104
  rtfToPdf(rtf: string): Uint8Array;
98
105
  /** Office (DOCX/ODT/PPTX/XLSX/ODS) → PDF, auto-detected. Empty array if unrecognized. */
99
106
  officeToPdf(office: Uint8Array): Uint8Array;
107
+ /**
108
+ * Image (PNG/JPEG/GIF/WebP/AVIF) → one-page PDF, format auto-detected: the
109
+ * image is centred and scaled to fit on an A4 portrait page. PNG/JPEG embed
110
+ * directly; GIF/WebP/AVIF are transcoded to PNG first — all in pure Rust/WASM,
111
+ * no third-party image library. Empty array if the bytes are not a recognized
112
+ * image. To combine many images into a single document, pipe each result
113
+ * through {@link mergePdfs}.
114
+ */
115
+ imageToPdf(image: Uint8Array): Uint8Array;
116
+ /**
117
+ * Merge several PDFs into one by appending their pages in order. Returns an
118
+ * empty document for an empty list, or the single input unchanged for a list
119
+ * of one. Each subsequent PDF is appended onto the first via
120
+ * {@link GigaPdfDoc.appendPages}; the merged bytes are returned and the working
121
+ * document is closed.
122
+ */
123
+ mergePdfs(pdfs: Uint8Array[]): Uint8Array;
100
124
  /**
101
125
  * Write a host-built grid (`pages[rows][cells]`) to an `.xlsx` workbook — one
102
126
  * sheet per page — with the engine's native spreadsheet writer (no
@@ -185,7 +209,10 @@ declare class GigaPdfEngine {
185
209
  * the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
186
210
  * from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
187
211
  * on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
188
- * Bengali, Tamil) or to upgrade Latin/Cyrillic/Greek to the CRNN (`alpha`).
212
+ * Bengali, Tamil, Chinese `cjk`, Japanese, Korean) or to upgrade
213
+ * Latin/Cyrillic/Greek to the CRNN (`alpha`). Returns `false` (rather than
214
+ * throwing) when the blob isn't bundled in this release — e.g. a script still
215
+ * training upstream — so loading a set stays resilient.
189
216
  */
190
217
  loadBundledOcrModel(script: OcrScript): Promise<boolean>;
191
218
  /**
package/dist/index.d.ts CHANGED
@@ -21,12 +21,19 @@ type Exports = {
21
21
  /**
22
22
  * A trained per-script OCR model bundled with the package. `alpha` covers
23
23
  * Latin, Cyrillic and Greek; `arabic` is the **RTL group** (Arabic, Urdu,
24
- * Hebrew); the rest are dedicated scripts. The matching `.gpocr` CRNN blob
25
- * ships under `models/` and is host-loaded on demand. To recognize any shipped
26
- * language at once (including models added later), prefer
24
+ * Hebrew); `cjk` is Chinese (2401-class); `japanese` / `korean` are their own
25
+ * groups (kana+kanji / Hangul, each + full ASCII for mixed alphanumerics); the
26
+ * rest are dedicated Indic scripts. The matching `.gpocr` CRNN blob ships under
27
+ * `models/` and is host-loaded on demand. To recognize any shipped language at
28
+ * once (including models added later), prefer
27
29
  * {@link GigaPdfEngine.loadAllBundledOcrModels}.
30
+ *
31
+ * Some models may not be bundled in every release (a script can still be
32
+ * training upstream) — {@link GigaPdfEngine.loadBundledOcrModel} returns `false`
33
+ * for an absent blob instead of throwing, so listing them in
34
+ * {@link ALL_OCR_SCRIPTS} stays safe.
28
35
  */
29
- type OcrScript = "alpha" | "arabic" | "devanagari" | "bengali" | "tamil";
36
+ type OcrScript = "alpha" | "arabic" | "devanagari" | "bengali" | "tamil" | "cjk" | "japanese" | "korean";
30
37
  /** Every trained script — load all for "recognize text in any language". */
31
38
  declare const ALL_OCR_SCRIPTS: readonly OcrScript[];
32
39
  /** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
@@ -97,6 +104,23 @@ declare class GigaPdfEngine {
97
104
  rtfToPdf(rtf: string): Uint8Array;
98
105
  /** Office (DOCX/ODT/PPTX/XLSX/ODS) → PDF, auto-detected. Empty array if unrecognized. */
99
106
  officeToPdf(office: Uint8Array): Uint8Array;
107
+ /**
108
+ * Image (PNG/JPEG/GIF/WebP/AVIF) → one-page PDF, format auto-detected: the
109
+ * image is centred and scaled to fit on an A4 portrait page. PNG/JPEG embed
110
+ * directly; GIF/WebP/AVIF are transcoded to PNG first — all in pure Rust/WASM,
111
+ * no third-party image library. Empty array if the bytes are not a recognized
112
+ * image. To combine many images into a single document, pipe each result
113
+ * through {@link mergePdfs}.
114
+ */
115
+ imageToPdf(image: Uint8Array): Uint8Array;
116
+ /**
117
+ * Merge several PDFs into one by appending their pages in order. Returns an
118
+ * empty document for an empty list, or the single input unchanged for a list
119
+ * of one. Each subsequent PDF is appended onto the first via
120
+ * {@link GigaPdfDoc.appendPages}; the merged bytes are returned and the working
121
+ * document is closed.
122
+ */
123
+ mergePdfs(pdfs: Uint8Array[]): Uint8Array;
100
124
  /**
101
125
  * Write a host-built grid (`pages[rows][cells]`) to an `.xlsx` workbook — one
102
126
  * sheet per page — with the engine's native spreadsheet writer (no
@@ -185,7 +209,10 @@ declare class GigaPdfEngine {
185
209
  * the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
186
210
  * from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
187
211
  * on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
188
- * Bengali, Tamil) or to upgrade Latin/Cyrillic/Greek to the CRNN (`alpha`).
212
+ * Bengali, Tamil, Chinese `cjk`, Japanese, Korean) or to upgrade
213
+ * Latin/Cyrillic/Greek to the CRNN (`alpha`). Returns `false` (rather than
214
+ * throwing) when the blob isn't bundled in this release — e.g. a script still
215
+ * training upstream — so loading a set stays resilient.
189
216
  */
190
217
  loadBundledOcrModel(script: OcrScript): Promise<boolean>;
191
218
  /**
package/dist/index.js CHANGED
@@ -11,14 +11,20 @@ var OCR_MODEL_FILES = {
11
11
  arabic: "ocr_arabic.gpocr",
12
12
  devanagari: "ocr_deva.gpocr",
13
13
  bengali: "ocr_beng.gpocr",
14
- tamil: "ocr_taml.gpocr"
14
+ tamil: "ocr_taml.gpocr",
15
+ cjk: "ocr_cjk.gpocr",
16
+ japanese: "ocr_jpn.gpocr",
17
+ korean: "ocr_kor.gpocr"
15
18
  };
16
19
  var ALL_OCR_SCRIPTS = [
17
20
  "alpha",
18
21
  "arabic",
19
22
  "devanagari",
20
23
  "bengali",
21
- "tamil"
24
+ "tamil",
25
+ "cjk",
26
+ "japanese",
27
+ "korean"
22
28
  ];
23
29
  var GigaPdfEngine = class _GigaPdfEngine {
24
30
  constructor(ex) {
@@ -240,6 +246,40 @@ var GigaPdfEngine = class _GigaPdfEngine {
240
246
  (p, l) => this._buffer((o) => this.ex.gp_office_to_pdf(p, l, o))
241
247
  );
242
248
  }
249
+ /**
250
+ * Image (PNG/JPEG/GIF/WebP/AVIF) → one-page PDF, format auto-detected: the
251
+ * image is centred and scaled to fit on an A4 portrait page. PNG/JPEG embed
252
+ * directly; GIF/WebP/AVIF are transcoded to PNG first — all in pure Rust/WASM,
253
+ * no third-party image library. Empty array if the bytes are not a recognized
254
+ * image. To combine many images into a single document, pipe each result
255
+ * through {@link mergePdfs}.
256
+ */
257
+ imageToPdf(image) {
258
+ return this._withBytes(
259
+ image,
260
+ (p, l) => this._buffer((o) => this.ex.gp_image_to_pdf(p, l, o))
261
+ );
262
+ }
263
+ /**
264
+ * Merge several PDFs into one by appending their pages in order. Returns an
265
+ * empty document for an empty list, or the single input unchanged for a list
266
+ * of one. Each subsequent PDF is appended onto the first via
267
+ * {@link GigaPdfDoc.appendPages}; the merged bytes are returned and the working
268
+ * document is closed.
269
+ */
270
+ mergePdfs(pdfs) {
271
+ if (pdfs.length === 0) return new Uint8Array(0);
272
+ if (pdfs.length === 1) return pdfs[0];
273
+ const base = this.open(pdfs[0]);
274
+ try {
275
+ for (let i = 1; i < pdfs.length; i++) {
276
+ base.appendPages(pdfs[i]);
277
+ }
278
+ return base.save();
279
+ } finally {
280
+ base.close();
281
+ }
282
+ }
243
283
  /**
244
284
  * Write a host-built grid (`pages[rows][cells]`) to an `.xlsx` workbook — one
245
285
  * sheet per page — with the engine's native spreadsheet writer (no
@@ -389,10 +429,17 @@ var GigaPdfEngine = class _GigaPdfEngine {
389
429
  * the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
390
430
  * from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
391
431
  * on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
392
- * Bengali, Tamil) or to upgrade Latin/Cyrillic/Greek to the CRNN (`alpha`).
432
+ * Bengali, Tamil, Chinese `cjk`, Japanese, Korean) or to upgrade
433
+ * Latin/Cyrillic/Greek to the CRNN (`alpha`). Returns `false` (rather than
434
+ * throwing) when the blob isn't bundled in this release — e.g. a script still
435
+ * training upstream — so loading a set stays resilient.
393
436
  */
394
437
  async loadBundledOcrModel(script) {
395
- return this.loadOcrModel(await readModelFile(OCR_MODEL_FILES[script]));
438
+ try {
439
+ return this.loadOcrModel(await readModelFile(OCR_MODEL_FILES[script]));
440
+ } catch {
441
+ return false;
442
+ }
396
443
  }
397
444
  /**
398
445
  * Load several bundled OCR models (idempotent per call). Returns the scripts