@qrcommunication/gigapdf-lib 0.63.0 → 0.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/dist/index.cjs +34 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -63
- package/dist/index.d.ts +18 -63
- package/dist/index.js +35 -123
- package/dist/index.js.map +1 -1
- package/dist/node-fs.browser.cjs +3 -13
- package/dist/node-fs.browser.cjs.map +1 -1
- package/dist/node-fs.browser.d.cts +3 -10
- package/dist/node-fs.browser.d.ts +3 -10
- package/dist/node-fs.browser.js +2 -10
- package/dist/node-fs.browser.js.map +1 -1
- package/dist/node-fs.cjs +2 -37
- package/dist/node-fs.cjs.map +1 -1
- package/dist/node-fs.d.cts +1 -11
- package/dist/node-fs.d.ts +1 -11
- package/dist/node-fs.js +1 -34
- package/dist/node-fs.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
- package/models/ocr_alpha.gpocr +0 -0
- package/models/ocr_alpha_big.gpocr +0 -0
- package/models/ocr_alpha_hw.gpocr +0 -0
- package/models/ocr_alpha_photo.gpocr +0 -0
- package/models/ocr_alpha_print.gpocr +0 -0
- package/models/ocr_arabic.gpocr +0 -0
- package/models/ocr_arabic_small.gpocr +0 -0
- package/models/ocr_beng.gpocr +0 -0
- package/models/ocr_beng_small.gpocr +0 -0
- package/models/ocr_cjk.gpocr +0 -0
- package/models/ocr_deva.gpocr +0 -0
- package/models/ocr_deva_small.gpocr +0 -0
- package/models/ocr_jpn.gpocr +0 -0
- package/models/ocr_kann.gpocr +0 -0
- package/models/ocr_kor.gpocr +0 -0
- package/models/ocr_mlym.gpocr +0 -0
- package/models/ocr_taml.gpocr +0 -0
- package/models/ocr_taml_small.gpocr +0 -0
- package/models/ocr_telu.gpocr +0 -0
- package/models/ocr_thai.gpocr +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,44 @@ All notable changes to `@qrcommunication/gigapdf-lib` are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/) and the
|
|
5
5
|
project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.64.0] - 2026-06-22
|
|
8
|
+
|
|
9
|
+
Office↔PDF fidelity program — import all formats → PDF and export PDF → all
|
|
10
|
+
formats much closer to 1:1, including complex layouts (boxes/encadrés).
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Office→PDF preserves absolute layout** — presentation/box geometry is no
|
|
15
|
+
longer reflowed into a flat stack. PPTX/ODP shapes, images and tables carrying
|
|
16
|
+
an explicit `a:xfrm` / `draw:frame` are emitted at their exact coordinates
|
|
17
|
+
(EMU/ODF units → pt), with slide backgrounds and `a:schemeClr` theme colours
|
|
18
|
+
resolved. DOCX floating/anchored drawings (`wp:anchor`) and text boxes
|
|
19
|
+
(`w:txbxContent`) become absolutely-positioned frames (the “encadrés”), and
|
|
20
|
+
explicit page breaks (`w:br type=page`, `w:pageBreakBefore`, section breaks)
|
|
21
|
+
are honoured.
|
|
22
|
+
- **XLSX/ODS render with cell styling** — fonts (bold/italic/underline/size/
|
|
23
|
+
colour/family), borders, alignment and row heights are read from each cell's
|
|
24
|
+
style and applied at render (theme colours resolved); ODS cells were previously
|
|
25
|
+
unstyled. Merges, column widths and number formats unchanged.
|
|
26
|
+
- **PDF→Office export preserves absolute layout** — text boxes, images and vector
|
|
27
|
+
rectangles/paths (fill/stroke/dash) are exported at their exact coordinates for
|
|
28
|
+
PPTX/ODP/DOCX/ODT, so an exported deck/doc opened in PowerPoint/Word/Impress/
|
|
29
|
+
Writer looks like the source PDF, encadrés included.
|
|
30
|
+
- **Office→PDF embeds the document's own fonts** — a self-embedding DOCX/PPTX/
|
|
31
|
+
XLSX (`word|ppt|xl/fonts/*.odttf`, de-obfuscated per ECMA-376 §17.8.1) or ODT/
|
|
32
|
+
ODS/ODP (`Fonts/*`, TTF/OTF) renders with its **own** typefaces (exact glyphs
|
|
33
|
+
and metrics, no reflow drift) instead of the bundled Liberation fallback.
|
|
34
|
+
- **`officeNeededFonts(office)` / `gp_office_needed_fonts`** — phase-1 for
|
|
35
|
+
`officeToPdf`: returns the fonts a container **references but doesn't embed**
|
|
36
|
+
(`HtmlFontRequest[]`), so the host can fetch metric clones (Carlito↔Calibri,
|
|
37
|
+
Arimo↔Arial, …) into its font cache for correct line-breaking. `null` for an
|
|
38
|
+
unrecognized archive, `[]` when nothing is needed.
|
|
39
|
+
- **Stateful RTF rendering** — `rtfToPdf` now uses a real RTF parser with a `{}`
|
|
40
|
+
group state stack: character styling (`\b \i \ul \strike \cf \fs \f` via
|
|
41
|
+
font/colour tables), paragraph alignment/indents (`\qc\qr\qj\li\fi`), tables
|
|
42
|
+
(`\trowd\cell\row`) and correct CP1252 (`\'80`→€, smart quotes, dashes) instead
|
|
43
|
+
of the previous text-only extraction.
|
|
44
|
+
|
|
7
45
|
## [0.63.0] - 2026-06-22
|
|
8
46
|
|
|
9
47
|
### Changed
|
package/dist/index.cjs
CHANGED
|
@@ -20,7 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
ALL_OCR_SCRIPTS: () => ALL_OCR_SCRIPTS,
|
|
24
23
|
GigaPdfDoc: () => GigaPdfDoc,
|
|
25
24
|
GigaPdfEngine: () => GigaPdfEngine
|
|
26
25
|
});
|
|
@@ -28,54 +27,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
27
|
var import_node_fs = require("./node-fs.js");
|
|
29
28
|
var enc = new TextEncoder();
|
|
30
29
|
var dec = new TextDecoder();
|
|
31
|
-
var OCR_MODEL_FILES = {
|
|
32
|
-
alpha: "ocr_alpha.gpocr",
|
|
33
|
-
arabic: "ocr_arabic.gpocr",
|
|
34
|
-
devanagari: "ocr_deva.gpocr",
|
|
35
|
-
bengali: "ocr_beng.gpocr",
|
|
36
|
-
tamil: "ocr_taml.gpocr",
|
|
37
|
-
cjk: "ocr_cjk.gpocr",
|
|
38
|
-
japanese: "ocr_jpn.gpocr",
|
|
39
|
-
korean: "ocr_kor.gpocr",
|
|
40
|
-
thai: "ocr_thai.gpocr",
|
|
41
|
-
telugu: "ocr_telu.gpocr",
|
|
42
|
-
kannada: "ocr_kann.gpocr",
|
|
43
|
-
malayalam: "ocr_mlym.gpocr",
|
|
44
|
-
gujarati: "ocr_gujr.gpocr",
|
|
45
|
-
gurmukhi: "ocr_guru.gpocr",
|
|
46
|
-
oriya: "ocr_orya.gpocr",
|
|
47
|
-
sinhala: "ocr_sinh.gpocr",
|
|
48
|
-
georgian: "ocr_geor.gpocr",
|
|
49
|
-
armenian: "ocr_armn.gpocr",
|
|
50
|
-
khmer: "ocr_khmr.gpocr",
|
|
51
|
-
lao: "ocr_laoo.gpocr",
|
|
52
|
-
myanmar: "ocr_mymr.gpocr",
|
|
53
|
-
amharic: "ocr_ethi.gpocr"
|
|
54
|
-
};
|
|
55
|
-
var ALL_OCR_SCRIPTS = [
|
|
56
|
-
"alpha",
|
|
57
|
-
"arabic",
|
|
58
|
-
"devanagari",
|
|
59
|
-
"bengali",
|
|
60
|
-
"tamil",
|
|
61
|
-
"cjk",
|
|
62
|
-
"japanese",
|
|
63
|
-
"korean",
|
|
64
|
-
"thai",
|
|
65
|
-
"telugu",
|
|
66
|
-
"kannada",
|
|
67
|
-
"malayalam",
|
|
68
|
-
"gujarati",
|
|
69
|
-
"gurmukhi",
|
|
70
|
-
"oriya",
|
|
71
|
-
"sinhala",
|
|
72
|
-
"georgian",
|
|
73
|
-
"armenian",
|
|
74
|
-
"khmer",
|
|
75
|
-
"lao",
|
|
76
|
-
"myanmar",
|
|
77
|
-
"amharic"
|
|
78
|
-
];
|
|
79
30
|
var GigaPdfEngine = class _GigaPdfEngine {
|
|
80
31
|
constructor(ex) {
|
|
81
32
|
this.ex = ex;
|
|
@@ -166,6 +117,26 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
166
117
|
const s = this._str(call);
|
|
167
118
|
return s ? JSON.parse(s) : [];
|
|
168
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Like {@link _json} but distinguishes a **null** result (the export returned a
|
|
122
|
+
* null pointer — e.g. an unrecognized container) from a present-but-empty JSON
|
|
123
|
+
* payload (`[]` / `{}`). Returns `null` only for the null pointer; otherwise the
|
|
124
|
+
* parsed JSON. Used where the Rust side is `Option<…>` and "nothing" and
|
|
125
|
+
* "unrecognized" must stay distinct.
|
|
126
|
+
*/
|
|
127
|
+
_jsonOrNull(call) {
|
|
128
|
+
const lenPtr = this.ex.gp_alloc(4);
|
|
129
|
+
const dataPtr = call(lenPtr);
|
|
130
|
+
if (dataPtr === 0) {
|
|
131
|
+
this.ex.gp_free(lenPtr, 4);
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const len = this.dv().getUint32(lenPtr, true);
|
|
135
|
+
const s = dec.decode(this.u8().slice(dataPtr, dataPtr + len));
|
|
136
|
+
this.ex.gp_free(dataPtr, len);
|
|
137
|
+
this.ex.gp_free(lenPtr, 4);
|
|
138
|
+
return s ? JSON.parse(s) : [];
|
|
139
|
+
}
|
|
169
140
|
/**
|
|
170
141
|
* Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
|
|
171
142
|
* works identically in Node and the browser with no dependency (used to turn
|
|
@@ -296,6 +267,20 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
296
267
|
(p, l) => this._buffer((o) => this.ex.gp_office_to_pdf(p, l, o))
|
|
297
268
|
);
|
|
298
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Phase 1 for {@link officeToPdf} — the Google/system fonts an Office container
|
|
272
|
+
* **references but doesn't embed**. Download each `url` (→ TTF) and supply the
|
|
273
|
+
* bytes back to the host font cache so {@link officeToPdf}'s styled runs lay out
|
|
274
|
+
* with the right metrics. Faces the container embeds itself are de-obfuscated
|
|
275
|
+
* and used automatically (not listed here). Returns `null` if the bytes are not
|
|
276
|
+
* a recognized Office container, `[]` if it needs no host fonts.
|
|
277
|
+
*/
|
|
278
|
+
officeNeededFonts(office) {
|
|
279
|
+
return this._withBytes(
|
|
280
|
+
office,
|
|
281
|
+
(p, l) => this._jsonOrNull((o) => this.ex.gp_office_needed_fonts(p, l, o))
|
|
282
|
+
);
|
|
283
|
+
}
|
|
299
284
|
/**
|
|
300
285
|
* Image (PNG/JPEG/GIF/WebP/AVIF) → one-page PDF, format auto-detected: the
|
|
301
286
|
* image is centred and scaled to fit on an A4 portrait page. PNG/JPEG embed
|
|
@@ -457,68 +442,6 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
457
442
|
const dv = new DataView(framed.buffer, framed.byteOffset, framed.byteLength);
|
|
458
443
|
return { width: dv.getUint32(0, true), height: dv.getUint32(4, true), rgba: framed.subarray(8) };
|
|
459
444
|
}
|
|
460
|
-
// ── OCR models (host-loaded `.gpocr` blobs — multi-script line recognizer) ─
|
|
461
|
-
/**
|
|
462
|
-
* Load a `.gpocr` line-level OCR model blob into the engine's runtime registry
|
|
463
|
-
* — Latin/Cyrillic/Greek (`alpha`), Arabic (RTL), Devanagari, Bengali, Tamil…
|
|
464
|
-
* The host supplies the bytes (the wasm ships no weights, like fonts), so the
|
|
465
|
-
* module stays lean. Once loaded, {@link GigaPdfDoc.ocr} / {@link GigaPdfDoc.ocrText}
|
|
466
|
-
* route to the CRNN+CTC line recognizer (per-page fallback to the built-in
|
|
467
|
-
* mono-glyph Latin classifier). Models are global to the engine; call after
|
|
468
|
-
* `load`/`loadDefault`. Returns `true` on success, `false` on a malformed blob.
|
|
469
|
-
*/
|
|
470
|
-
loadOcrModel(model) {
|
|
471
|
-
return this._withBytes(model, (p, l) => this.ex.gp_ocr_load_model(p, l)) === 1;
|
|
472
|
-
}
|
|
473
|
-
/** Drop every runtime-loaded OCR model (reverts to the mono-glyph classifier). */
|
|
474
|
-
clearOcrModels() {
|
|
475
|
-
this.ex.gp_ocr_clear_models();
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Resolve a bundled `.gpocr` model (shipped under `models/`) and load it into
|
|
479
|
-
* the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
|
|
480
|
-
* from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
|
|
481
|
-
* on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
|
|
482
|
-
* Bengali, Tamil, Chinese `cjk`, Japanese, Korean) or to upgrade
|
|
483
|
-
* Latin/Cyrillic/Greek to the CRNN (`alpha`). Returns `false` (rather than
|
|
484
|
-
* throwing) when the blob isn't bundled in this release — e.g. a script still
|
|
485
|
-
* training upstream — so loading a set stays resilient.
|
|
486
|
-
*/
|
|
487
|
-
async loadBundledOcrModel(script) {
|
|
488
|
-
try {
|
|
489
|
-
return this.loadOcrModel(await (0, import_node_fs.readModelFile)(OCR_MODEL_FILES[script]));
|
|
490
|
-
} catch {
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Load several bundled OCR models (idempotent per call). Returns the scripts
|
|
496
|
-
* that loaded successfully. Pass {@link ALL_OCR_SCRIPTS} to recognize text in
|
|
497
|
-
* any supported language; the engine's script detector routes each line to the
|
|
498
|
-
* right model.
|
|
499
|
-
*/
|
|
500
|
-
async loadBundledOcrModels(scripts) {
|
|
501
|
-
const loaded = [];
|
|
502
|
-
for (const script of scripts) {
|
|
503
|
-
if (await this.loadBundledOcrModel(script)) loaded.push(script);
|
|
504
|
-
}
|
|
505
|
-
return loaded;
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Discover and load EVERY bundled `.gpocr` model (Node hosts only). The
|
|
509
|
-
* engine's script detector then routes each recognized line to the matching
|
|
510
|
-
* model, so the OCR recognizes text in any shipped script — Latin, Cyrillic,
|
|
511
|
-
* Greek, Arabic, Urdu, Hebrew (the RTL group), Devanagari, Bengali, Tamil, and
|
|
512
|
-
* any model added later — with no code change. Returns the number loaded.
|
|
513
|
-
*/
|
|
514
|
-
async loadAllBundledOcrModels() {
|
|
515
|
-
const models = await (0, import_node_fs.readModelsDir)();
|
|
516
|
-
let count = 0;
|
|
517
|
-
for (const { bytes } of models) {
|
|
518
|
-
if (this.loadOcrModel(bytes)) count += 1;
|
|
519
|
-
}
|
|
520
|
-
return count;
|
|
521
|
-
}
|
|
522
445
|
// ── fonts (catalog / Google Fonts URL — the host performs the fetch) ───────
|
|
523
446
|
fontCatalog() {
|
|
524
447
|
return this._json((o) => this.ex.gp_font_catalog_json(o));
|
|
@@ -1016,13 +939,6 @@ var GigaPdfDoc = class {
|
|
|
1016
939
|
(p, l) => this.g._json((o) => this.ex().gp_search_json(this.h, p, l, caseInsensitive ? 1 : 0, o))
|
|
1017
940
|
);
|
|
1018
941
|
}
|
|
1019
|
-
/** OCR a (scanned) page → words with PDF-space boxes. `scale` ≥ 2 for small text. */
|
|
1020
|
-
ocr(page, scale = 2) {
|
|
1021
|
-
return this.g._json((o) => this.ex().gp_ocr_json(this.h, page, scale, o));
|
|
1022
|
-
}
|
|
1023
|
-
ocrText(page, scale = 2) {
|
|
1024
|
-
return this.g._str((o) => this.ex().gp_ocr_text(this.h, page, scale, o));
|
|
1025
|
-
}
|
|
1026
942
|
// editing
|
|
1027
943
|
/**
|
|
1028
944
|
* Replace text run `index` on `page` with `text`. Font-aware: works with
|
|
@@ -2068,7 +1984,6 @@ var GigaPdfDoc = class {
|
|
|
2068
1984
|
};
|
|
2069
1985
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2070
1986
|
0 && (module.exports = {
|
|
2071
|
-
ALL_OCR_SCRIPTS,
|
|
2072
1987
|
GigaPdfDoc,
|
|
2073
1988
|
GigaPdfEngine
|
|
2074
1989
|
});
|