@qrcommunication/gigapdf-lib 0.16.0 → 0.18.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 +44 -0
- package/README.md +31 -8
- package/dist/index.cjs +90 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +73 -2
- package/dist/index.d.ts +73 -2
- package/dist/index.js +90 -3
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,50 @@ 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.18.0] - 2026-06-16
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **Text in *any* font — OpenType-CFF embedding.** `embedFont(family, font)`
|
|
12
|
+
(Rust `embed_font`, alias `embed_truetype_font`) now accepts **any** outline
|
|
13
|
+
program and auto-detects the flavour: a glyf `.ttf` embeds as Type0 /
|
|
14
|
+
CIDFontType2 + `FontFile2` (as before), and an **OpenType-CFF** `.otf`
|
|
15
|
+
(`OTTO`) embeds as Type0 / CIDFontType0 + `FontFile3` `/Subtype /OpenType`.
|
|
16
|
+
Both are Identity-H with a full `/W` width array and a `/ToUnicode` CMap, so
|
|
17
|
+
`addText` draws selectable, copy-able text in `.otf` fonts too.
|
|
18
|
+
- **Font-aware text editing.** `replaceText` (Rust `replace_text_run`) is now
|
|
19
|
+
font-aware: a run set in an embedded Type0/Identity-H face (TrueType **or**
|
|
20
|
+
OpenType-CFF) is re-encoded through that font's char→glyph map — so **modify**
|
|
21
|
+
works with any font, not just base-14/WinAnsi. `addText` and `replaceText`
|
|
22
|
+
also resolve a document's *own* embedded faces from `FontFile2` **or**
|
|
23
|
+
`FontFile3`, completing "draw/edit text in the exact original face".
|
|
24
|
+
- **Named destinations.** `addNamedDest(name, page)`, `namedDests()` and
|
|
25
|
+
`addGotoLinkNamed(page, x0,y0,x1,y1, name)` (Rust `add_named_dest` /
|
|
26
|
+
`named_dests` / `add_goto_link_named`; ABI `gp_add_named_dest`,
|
|
27
|
+
`gp_named_dests_json`, `gp_add_goto_link_named`) register and link to catalog
|
|
28
|
+
`/Dests` by name. Resolution goes through the catalog, so a named anchor is
|
|
29
|
+
retargetable and survives page split/extract while its page is kept. New
|
|
30
|
+
`NamedDest` type.
|
|
31
|
+
|
|
32
|
+
## [0.17.0] - 2026-06-16
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
- **`doc.addStandardText(page, x, y, size, text, fontName, …)`** — draw real,
|
|
37
|
+
selectable text in a built-in **base-14 standard font** (`Helvetica`/`Times`/
|
|
38
|
+
`Courier` × 4 styles + `Symbol` + `ZapfDingbats`) with **no embedding**. Several
|
|
39
|
+
different standard fonts can now coexist on one page. (`add_text` still covers
|
|
40
|
+
arbitrary families via an embedded TrueType.)
|
|
41
|
+
- **`doc.embeddedFonts()`** — list the fonts a PDF already carries, each
|
|
42
|
+
`{ baseFont, format: "truetype" | "cff" | "type1" }`. Paired with the existing
|
|
43
|
+
`extractFont(name)`, you can pull a document's own font program out and
|
|
44
|
+
re-embed it (`embedFont`) to draw new text in the exact original face — the
|
|
45
|
+
complete "reuse the document's fonts" path, all native.
|
|
46
|
+
|
|
47
|
+
This rounds out native text drawing to **every font source**: the 14 standard
|
|
48
|
+
fonts (no files), any TrueType/Google Font (embed), and a document's own
|
|
49
|
+
embedded faces (extract + re-embed).
|
|
50
|
+
|
|
7
51
|
## [0.16.0] - 2026-06-16
|
|
8
52
|
|
|
9
53
|
### Added
|
package/README.md
CHANGED
|
@@ -73,15 +73,30 @@ doc.addTextField(1, "vat", [50, 510, 200, 528], "", {
|
|
|
73
73
|
const filled = doc.fields(); // read them straight back: kind + value + options
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
### Fonts
|
|
76
|
+
### Fonts — three sources, no host font files required
|
|
77
77
|
|
|
78
78
|
```ts
|
|
79
|
+
// 1. Base-14 standard fonts — no embedding, no network.
|
|
80
|
+
doc.addStandardText(1, 72, 720, 24, "Heading", "Helvetica-Bold", 0x111111);
|
|
81
|
+
doc.addStandardText(1, 72, 690, 12, "body in Times", "Times-Roman");
|
|
82
|
+
|
|
83
|
+
// 2. Any family / Google Font — the host fetches, the engine embeds. embedFont
|
|
84
|
+
// accepts any outline file: glyf .ttf OR OpenType-CFF .otf (auto-detected).
|
|
79
85
|
const url = giga.fontRequestUrl("Roboto", 400); // Google Fonts CSS2 URL
|
|
80
86
|
const css = await (await fetch(url, { headers: { "User-Agent": "Mozilla/4.0" } })).text();
|
|
81
|
-
const
|
|
82
|
-
const ttf = new Uint8Array(await (await fetch(ttfUrl)).arrayBuffer());
|
|
87
|
+
const ttf = new Uint8Array(await (await fetch(giga.parseCssFontUrl(css))).arrayBuffer());
|
|
83
88
|
const fontObj = doc.embedFont("Roboto", ttf);
|
|
84
|
-
doc.addText(1, 72,
|
|
89
|
+
doc.addText(1, 72, 660, 18, "Selectable embedded text", fontObj, 0x111111);
|
|
90
|
+
// Font-aware editing: replace the run's text — re-encoded through Roboto's cmap.
|
|
91
|
+
doc.replaceText(1, doc.textRuns(1).length - 1, "Edited in the same font");
|
|
92
|
+
|
|
93
|
+
// 3. Reuse a face the PDF already embeds: list → extract → re-embed → draw.
|
|
94
|
+
const face = doc.embeddedFonts().find((f) => f.format === "truetype");
|
|
95
|
+
if (face) {
|
|
96
|
+
const prog = doc.extractFont(face.baseFont)!; // { format, bytes }
|
|
97
|
+
const reused = doc.embedFont("Reused", prog.bytes);
|
|
98
|
+
doc.addText(1, 72, 630, 14, "drawn in the document's own font", reused);
|
|
99
|
+
}
|
|
85
100
|
```
|
|
86
101
|
|
|
87
102
|
## Next.js (`output: "standalone"`)
|
|
@@ -101,6 +116,10 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
|
|
|
101
116
|
|
|
102
117
|
## API surface
|
|
103
118
|
|
|
119
|
+
> **Full, per-method reference:** [`docs/SDK.md`](https://github.com/QrCommunication/gigapdf-lib/blob/main/docs/SDK.md)
|
|
120
|
+
> documents every method (parameters, return, notes) grouped by domain. Exact
|
|
121
|
+
> signatures and defaults also ship in the bundled `.d.ts`.
|
|
122
|
+
|
|
104
123
|
- **`GigaPdfEngine`** — `load`/`loadDefault`, `open`/`openEncrypted`,
|
|
105
124
|
`txtToPdf`/`htmlToPdf`/`rtfToPdf`/`officeToPdf`, `fontCatalog`/`fontRequestUrl`/`parseCssFontUrl`.
|
|
106
125
|
- **`GigaPdfDoc`** — text intelligence (`textRuns`, `structuredText`, `search`,
|
|
@@ -110,12 +129,16 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
|
|
|
110
129
|
`addImage` (PNG/JPEG, alpha + opacity)), pages (`rotatePage`, `deletePage`,
|
|
111
130
|
`movePage`, `appendPages`, `extractPages`, `resizePage`, `addPage`, `copyPage`,
|
|
112
131
|
`pageInfo`),
|
|
113
|
-
`renderPage`, fonts (
|
|
114
|
-
|
|
115
|
-
|
|
132
|
+
`renderPage`, fonts (base-14 `addStandardText`, embed **any** TrueType/OpenType
|
|
133
|
+
via `embedFont`/`addText`, font-aware editing `replaceText`,
|
|
134
|
+
the document's own faces `embeddedFonts`/`extractFont`, `neededFonts`),
|
|
135
|
+
conversions (`toText/Html/Docx/Pptx/Odp/Odt/Xlsx/Ods/Rtf/PdfA`), security
|
|
136
|
+
(`saveEncrypted`, self-signed `sign`, **PKCS#12** `signP12`), metadata
|
|
137
|
+
(`getMetadata`, `setMetadata`), annotations (`addSquare`,
|
|
116
138
|
`addHighlight`, `addLineAnnotation`, `addFreeText`, `addUnderline`,
|
|
117
139
|
`addStrikeOut`, `addInk`, `addStamp`, `annotations`, `removeAnnotation`,
|
|
118
|
-
`flattenAnnotations`), links (`links`, `addUriLink`, `addGotoLink
|
|
140
|
+
`flattenAnnotations`), links (`links`, `addUriLink`, `addGotoLink`, named
|
|
141
|
+
destinations `addNamedDest`/`namedDests`/`addGotoLinkNamed`), outline
|
|
119
142
|
(`outline`, `setOutline`), forms — read/fill (`fields`, `setTextField`,
|
|
120
143
|
`setCheckbox`, `setRadio`, `setChoice`) **and create**
|
|
121
144
|
(`addTextField`, `addCheckbox`, `addRadioGroup`, `addComboBox`, `addListBox`,
|
package/dist/index.cjs
CHANGED
|
@@ -463,6 +463,12 @@ var GigaPdfDoc = class {
|
|
|
463
463
|
return this.g._str((o) => this.ex().gp_ocr_text(this.h, page, scale, o));
|
|
464
464
|
}
|
|
465
465
|
// editing
|
|
466
|
+
/**
|
|
467
|
+
* Replace text run `index` on `page` with `text`. Font-aware: works with
|
|
468
|
+
* **any** font — a run set in an embedded Type0/Identity-H face (TrueType or
|
|
469
|
+
* OpenType-CFF) is re-encoded through that font's char→glyph map; base-14 and
|
|
470
|
+
* simple fonts use WinAnsi. Returns `false` if the run/page doesn't exist.
|
|
471
|
+
*/
|
|
466
472
|
replaceText(page, index, text) {
|
|
467
473
|
return this.g._withStr(text, (p, l) => this.ex().gp_replace_text(this.h, page, index, p, l)) === 0;
|
|
468
474
|
}
|
|
@@ -666,17 +672,33 @@ var GigaPdfDoc = class {
|
|
|
666
672
|
renderPage(page, scale = 1) {
|
|
667
673
|
return this.g._buffer((o) => this.ex().gp_render_page(this.h, page, scale, o));
|
|
668
674
|
}
|
|
669
|
-
// fonts — embed a downloaded
|
|
670
|
-
|
|
675
|
+
// fonts — embed a downloaded font, then add real selectable text
|
|
676
|
+
/**
|
|
677
|
+
* Embed an outline font program as a Type0 font and return its object number
|
|
678
|
+
* (pass to {@link addText} / re-encoded by {@link replaceText}). Accepts
|
|
679
|
+
* **any** font file — glyf **TrueType** (`.ttf`) or **OpenType-CFF**
|
|
680
|
+
* (`.otf`/`OTTO`), flavour auto-detected — so `font` may be a Google Font the
|
|
681
|
+
* host fetched, an `.otf` you supply, or a face pulled out of a document with
|
|
682
|
+
* {@link extractFont}. Returns 0 on a malformed/unsupported program.
|
|
683
|
+
*/
|
|
684
|
+
embedFont(family, font) {
|
|
671
685
|
const b = enc.encode(family);
|
|
672
686
|
const famPtr = this.g._toWasm(b);
|
|
673
687
|
const obj = this.g._withBytes(
|
|
674
|
-
|
|
688
|
+
font,
|
|
675
689
|
(p, l) => this.ex().gp_embed_font(this.h, famPtr, b.length, p, l)
|
|
676
690
|
);
|
|
677
691
|
this.g._free(famPtr, b.length);
|
|
678
692
|
return obj;
|
|
679
693
|
}
|
|
694
|
+
/**
|
|
695
|
+
* Draw real, selectable text at `(x, y)` (PDF points, origin bottom-left) in a
|
|
696
|
+
* font embedded with {@link embedFont} (`fontObj`). Works with **any** embedded
|
|
697
|
+
* face — glyf TrueType or OpenType-CFF — encoding each character through the
|
|
698
|
+
* font's char→glyph map (Identity-H, 2-byte glyph ids). `rgb` is packed
|
|
699
|
+
* `0xRRGGBB`; `rotationDeg` rotates CCW about `(x, y)`. For a built-in base-14
|
|
700
|
+
* family with no embedding, use {@link addStandardText}.
|
|
701
|
+
*/
|
|
680
702
|
addText(page, x, y, size, text, fontObj, rgb = 0, opacity = 1, rotationDeg = 0) {
|
|
681
703
|
return this.g._withStr(
|
|
682
704
|
text,
|
|
@@ -695,6 +717,36 @@ var GigaPdfDoc = class {
|
|
|
695
717
|
)
|
|
696
718
|
) === 0;
|
|
697
719
|
}
|
|
720
|
+
/**
|
|
721
|
+
* Draw `text` at `(x, y)` in a built-in **base-14 standard font** (`fontName`,
|
|
722
|
+
* e.g. `"Times-Bold"`, `"Courier-Oblique"`, `"Symbol"`) — no embedding needed,
|
|
723
|
+
* every viewer ships these 14. For any other family embed a TrueType with
|
|
724
|
+
* {@link embedFont} (a Google Font fetched by the host, or one pulled out of
|
|
725
|
+
* the document with {@link extractFont}) and use {@link addText}. Returns
|
|
726
|
+
* `false` on an unknown font name or bad page.
|
|
727
|
+
*/
|
|
728
|
+
addStandardText(page, x, y, size, text, fontName, rgb = 0, opacity = 1, rotationDeg = 0) {
|
|
729
|
+
return this.g._withStr(
|
|
730
|
+
text,
|
|
731
|
+
(tp, tl) => this.g._withStr(
|
|
732
|
+
fontName,
|
|
733
|
+
(fp, fl) => this.ex().gp_add_text_standard(
|
|
734
|
+
this.h,
|
|
735
|
+
page,
|
|
736
|
+
x,
|
|
737
|
+
y,
|
|
738
|
+
size,
|
|
739
|
+
tp,
|
|
740
|
+
tl,
|
|
741
|
+
fp,
|
|
742
|
+
fl,
|
|
743
|
+
RGB(rgb),
|
|
744
|
+
opacity,
|
|
745
|
+
rotationDeg
|
|
746
|
+
)
|
|
747
|
+
)
|
|
748
|
+
) === 0;
|
|
749
|
+
}
|
|
698
750
|
/**
|
|
699
751
|
* Stamp a standard-**Helvetica** watermark (no font embed needed): `text` at
|
|
700
752
|
* `(x, y)`, rotated `rotationDeg`° counter-clockwise, `rgb` packed `0xRRGGBB`,
|
|
@@ -725,6 +777,15 @@ var GigaPdfDoc = class {
|
|
|
725
777
|
const format = buf[0] === 1 ? "truetype" : buf[0] === 2 ? "cff" : "type1";
|
|
726
778
|
return { format, bytes: buf.subarray(1) };
|
|
727
779
|
}
|
|
780
|
+
/**
|
|
781
|
+
* The fonts **embedded** in the document — each `{ baseFont, format }`. Pair
|
|
782
|
+
* with {@link extractFont} to pull a font's bytes out and re-embed them via
|
|
783
|
+
* {@link embedFont}, e.g. to draw new text (with {@link addText}) in a face
|
|
784
|
+
* the document already carries — no external font file needed.
|
|
785
|
+
*/
|
|
786
|
+
embeddedFonts() {
|
|
787
|
+
return this.g._json((o) => this.ex().gp_embedded_fonts_json(this.h, o));
|
|
788
|
+
}
|
|
728
789
|
// convert PDF → X
|
|
729
790
|
toText() {
|
|
730
791
|
return this.g._str((o) => this.ex().gp_to_text(this.h, o));
|
|
@@ -999,6 +1060,32 @@ var GigaPdfDoc = class {
|
|
|
999
1060
|
addGotoLink(page, x0, y0, x1, y1, targetPage) {
|
|
1000
1061
|
return this.ex().gp_add_goto_link(this.h, page, x0, y0, x1, y1, targetPage) === 0;
|
|
1001
1062
|
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Register a named destination `name` → `targetPage` (a whole-page `/Fit`
|
|
1065
|
+
* view) in the catalog. Links and bookmarks can then jump by name via
|
|
1066
|
+
* {@link addGotoLinkNamed}; because resolution goes through the catalog (not a
|
|
1067
|
+
* frozen page number), the anchor survives page extraction/split as long as
|
|
1068
|
+
* its page is kept. Re-using a `name` overwrites its target.
|
|
1069
|
+
*/
|
|
1070
|
+
addNamedDest(name, targetPage) {
|
|
1071
|
+
return this.g._withStr(name, (p, l) => this.ex().gp_add_named_dest(this.h, p, l, targetPage)) === 0;
|
|
1072
|
+
}
|
|
1073
|
+
/** The catalog's named destinations as `{name, page}` pairs. */
|
|
1074
|
+
namedDests() {
|
|
1075
|
+
return this.g._json((o) => this.ex().gp_named_dests_json(this.h, o));
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Add an internal hyperlink over a rectangle that jumps to the named
|
|
1079
|
+
* destination `name` (define it with {@link addNamedDest}). Unlike
|
|
1080
|
+
* {@link addGotoLink} (an explicit page), this stores `/Dest /name`, keeping
|
|
1081
|
+
* cross-references intact through split/extract.
|
|
1082
|
+
*/
|
|
1083
|
+
addGotoLinkNamed(page, x0, y0, x1, y1, name) {
|
|
1084
|
+
return this.g._withStr(
|
|
1085
|
+
name,
|
|
1086
|
+
(p, l) => this.ex().gp_add_goto_link_named(this.h, page, x0, y0, x1, y1, p, l)
|
|
1087
|
+
) === 0;
|
|
1088
|
+
}
|
|
1002
1089
|
// optional-content layers (calques): list + show/hide + lock/unlock + remove
|
|
1003
1090
|
layers() {
|
|
1004
1091
|
return this.g._json((o) => this.ex().gp_layers_json(this.h, o));
|