@qrcommunication/gigapdf-lib 0.17.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/dist/index.d.cts CHANGED
@@ -188,7 +188,11 @@ interface FontInfo {
188
188
  interface EmbeddedFont {
189
189
  /** The `/BaseFont` name (may carry a `ABCDEF+` subset prefix). */
190
190
  baseFont: string;
191
- /** Embedded program format. `truetype` re-embeds directly via `embedFont`. */
191
+ /**
192
+ * Embedded program format. `truetype` (glyf) and a full OpenType `cff`
193
+ * (`OTTO`) re-embed directly via {@link GigaPdfDoc.embedFont}; bare `cff`
194
+ * (Type1C) and `type1` are read-only here.
195
+ */
192
196
  format: "truetype" | "cff" | "type1";
193
197
  }
194
198
  interface Box {
@@ -280,6 +284,11 @@ interface OutlineEntry {
280
284
  title: string;
281
285
  page?: number;
282
286
  }
287
+ /** A named destination from {@link GigaPdfDoc.namedDests}: a name → page anchor. */
288
+ interface NamedDest {
289
+ name: string;
290
+ page: number;
291
+ }
283
292
  /** An optional-content layer (calque): toggle `visible`/`locked` to persist in the PDF. */
284
293
  interface LayerInfo {
285
294
  id: number;
@@ -331,6 +340,12 @@ declare class GigaPdfDoc {
331
340
  /** OCR a (scanned) page → words with PDF-space boxes. `scale` ≥ 2 for small text. */
332
341
  ocr(page: number, scale?: number): OcrWord[];
333
342
  ocrText(page: number, scale?: number): string;
343
+ /**
344
+ * Replace text run `index` on `page` with `text`. Font-aware: works with
345
+ * **any** font — a run set in an embedded Type0/Identity-H face (TrueType or
346
+ * OpenType-CFF) is re-encoded through that font's char→glyph map; base-14 and
347
+ * simple fonts use WinAnsi. Returns `false` if the run/page doesn't exist.
348
+ */
334
349
  replaceText(page: number, index: number, text: string): boolean;
335
350
  removeElement(page: number, index: number): boolean;
336
351
  moveElement(page: number, index: number, dx: number, dy: number): boolean;
@@ -403,7 +418,23 @@ declare class GigaPdfDoc {
403
418
  /** A page's size (points) and `/Rotate` (0/90/180/270). */
404
419
  pageInfo(page: number): PageInfo;
405
420
  renderPage(page: number, scale?: number): Uint8Array;
406
- embedFont(family: string, ttf: Uint8Array): number;
421
+ /**
422
+ * Embed an outline font program as a Type0 font and return its object number
423
+ * (pass to {@link addText} / re-encoded by {@link replaceText}). Accepts
424
+ * **any** font file — glyf **TrueType** (`.ttf`) or **OpenType-CFF**
425
+ * (`.otf`/`OTTO`), flavour auto-detected — so `font` may be a Google Font the
426
+ * host fetched, an `.otf` you supply, or a face pulled out of a document with
427
+ * {@link extractFont}. Returns 0 on a malformed/unsupported program.
428
+ */
429
+ embedFont(family: string, font: Uint8Array): number;
430
+ /**
431
+ * Draw real, selectable text at `(x, y)` (PDF points, origin bottom-left) in a
432
+ * font embedded with {@link embedFont} (`fontObj`). Works with **any** embedded
433
+ * face — glyf TrueType or OpenType-CFF — encoding each character through the
434
+ * font's char→glyph map (Identity-H, 2-byte glyph ids). `rgb` is packed
435
+ * `0xRRGGBB`; `rotationDeg` rotates CCW about `(x, y)`. For a built-in base-14
436
+ * family with no embedding, use {@link addStandardText}.
437
+ */
407
438
  addText(page: number, x: number, y: number, size: number, text: string, fontObj: number, rgb?: number, opacity?: number, rotationDeg?: number): boolean;
408
439
  /**
409
440
  * Draw `text` at `(x, y)` in a built-in **base-14 standard font** (`fontName`,
@@ -524,6 +555,23 @@ declare class GigaPdfDoc {
524
555
  links(page: number): LinkInfo[];
525
556
  addUriLink(page: number, x0: number, y0: number, x1: number, y1: number, uri: string): boolean;
526
557
  addGotoLink(page: number, x0: number, y0: number, x1: number, y1: number, targetPage: number): boolean;
558
+ /**
559
+ * Register a named destination `name` → `targetPage` (a whole-page `/Fit`
560
+ * view) in the catalog. Links and bookmarks can then jump by name via
561
+ * {@link addGotoLinkNamed}; because resolution goes through the catalog (not a
562
+ * frozen page number), the anchor survives page extraction/split as long as
563
+ * its page is kept. Re-using a `name` overwrites its target.
564
+ */
565
+ addNamedDest(name: string, targetPage: number): boolean;
566
+ /** The catalog's named destinations as `{name, page}` pairs. */
567
+ namedDests(): NamedDest[];
568
+ /**
569
+ * Add an internal hyperlink over a rectangle that jumps to the named
570
+ * destination `name` (define it with {@link addNamedDest}). Unlike
571
+ * {@link addGotoLink} (an explicit page), this stores `/Dest /name`, keeping
572
+ * cross-references intact through split/extract.
573
+ */
574
+ addGotoLinkNamed(page: number, x0: number, y0: number, x1: number, y1: number, name: string): boolean;
527
575
  layers(): LayerInfo[];
528
576
  /** Create a new (visible, unlocked) layer; returns its id (0 on error). */
529
577
  addLayer(name: string): number;
@@ -577,4 +625,4 @@ declare class GigaPdfDoc {
577
625
  }): boolean;
578
626
  }
579
627
 
580
- export { type AnnotationInfo, type Box, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type LayerInfo, type LinkInfo, type OcrWord, type OutlineEntry, type PageInfo, type RadioOption, type SearchHit, type SignP12Options, type TextLine, type TextRunInfo };
628
+ export { type AnnotationInfo, type Box, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type RadioOption, type SearchHit, type SignP12Options, type TextLine, type TextRunInfo };
package/dist/index.d.ts CHANGED
@@ -188,7 +188,11 @@ interface FontInfo {
188
188
  interface EmbeddedFont {
189
189
  /** The `/BaseFont` name (may carry a `ABCDEF+` subset prefix). */
190
190
  baseFont: string;
191
- /** Embedded program format. `truetype` re-embeds directly via `embedFont`. */
191
+ /**
192
+ * Embedded program format. `truetype` (glyf) and a full OpenType `cff`
193
+ * (`OTTO`) re-embed directly via {@link GigaPdfDoc.embedFont}; bare `cff`
194
+ * (Type1C) and `type1` are read-only here.
195
+ */
192
196
  format: "truetype" | "cff" | "type1";
193
197
  }
194
198
  interface Box {
@@ -280,6 +284,11 @@ interface OutlineEntry {
280
284
  title: string;
281
285
  page?: number;
282
286
  }
287
+ /** A named destination from {@link GigaPdfDoc.namedDests}: a name → page anchor. */
288
+ interface NamedDest {
289
+ name: string;
290
+ page: number;
291
+ }
283
292
  /** An optional-content layer (calque): toggle `visible`/`locked` to persist in the PDF. */
284
293
  interface LayerInfo {
285
294
  id: number;
@@ -331,6 +340,12 @@ declare class GigaPdfDoc {
331
340
  /** OCR a (scanned) page → words with PDF-space boxes. `scale` ≥ 2 for small text. */
332
341
  ocr(page: number, scale?: number): OcrWord[];
333
342
  ocrText(page: number, scale?: number): string;
343
+ /**
344
+ * Replace text run `index` on `page` with `text`. Font-aware: works with
345
+ * **any** font — a run set in an embedded Type0/Identity-H face (TrueType or
346
+ * OpenType-CFF) is re-encoded through that font's char→glyph map; base-14 and
347
+ * simple fonts use WinAnsi. Returns `false` if the run/page doesn't exist.
348
+ */
334
349
  replaceText(page: number, index: number, text: string): boolean;
335
350
  removeElement(page: number, index: number): boolean;
336
351
  moveElement(page: number, index: number, dx: number, dy: number): boolean;
@@ -403,7 +418,23 @@ declare class GigaPdfDoc {
403
418
  /** A page's size (points) and `/Rotate` (0/90/180/270). */
404
419
  pageInfo(page: number): PageInfo;
405
420
  renderPage(page: number, scale?: number): Uint8Array;
406
- embedFont(family: string, ttf: Uint8Array): number;
421
+ /**
422
+ * Embed an outline font program as a Type0 font and return its object number
423
+ * (pass to {@link addText} / re-encoded by {@link replaceText}). Accepts
424
+ * **any** font file — glyf **TrueType** (`.ttf`) or **OpenType-CFF**
425
+ * (`.otf`/`OTTO`), flavour auto-detected — so `font` may be a Google Font the
426
+ * host fetched, an `.otf` you supply, or a face pulled out of a document with
427
+ * {@link extractFont}. Returns 0 on a malformed/unsupported program.
428
+ */
429
+ embedFont(family: string, font: Uint8Array): number;
430
+ /**
431
+ * Draw real, selectable text at `(x, y)` (PDF points, origin bottom-left) in a
432
+ * font embedded with {@link embedFont} (`fontObj`). Works with **any** embedded
433
+ * face — glyf TrueType or OpenType-CFF — encoding each character through the
434
+ * font's char→glyph map (Identity-H, 2-byte glyph ids). `rgb` is packed
435
+ * `0xRRGGBB`; `rotationDeg` rotates CCW about `(x, y)`. For a built-in base-14
436
+ * family with no embedding, use {@link addStandardText}.
437
+ */
407
438
  addText(page: number, x: number, y: number, size: number, text: string, fontObj: number, rgb?: number, opacity?: number, rotationDeg?: number): boolean;
408
439
  /**
409
440
  * Draw `text` at `(x, y)` in a built-in **base-14 standard font** (`fontName`,
@@ -524,6 +555,23 @@ declare class GigaPdfDoc {
524
555
  links(page: number): LinkInfo[];
525
556
  addUriLink(page: number, x0: number, y0: number, x1: number, y1: number, uri: string): boolean;
526
557
  addGotoLink(page: number, x0: number, y0: number, x1: number, y1: number, targetPage: number): boolean;
558
+ /**
559
+ * Register a named destination `name` → `targetPage` (a whole-page `/Fit`
560
+ * view) in the catalog. Links and bookmarks can then jump by name via
561
+ * {@link addGotoLinkNamed}; because resolution goes through the catalog (not a
562
+ * frozen page number), the anchor survives page extraction/split as long as
563
+ * its page is kept. Re-using a `name` overwrites its target.
564
+ */
565
+ addNamedDest(name: string, targetPage: number): boolean;
566
+ /** The catalog's named destinations as `{name, page}` pairs. */
567
+ namedDests(): NamedDest[];
568
+ /**
569
+ * Add an internal hyperlink over a rectangle that jumps to the named
570
+ * destination `name` (define it with {@link addNamedDest}). Unlike
571
+ * {@link addGotoLink} (an explicit page), this stores `/Dest /name`, keeping
572
+ * cross-references intact through split/extract.
573
+ */
574
+ addGotoLinkNamed(page: number, x0: number, y0: number, x1: number, y1: number, name: string): boolean;
527
575
  layers(): LayerInfo[];
528
576
  /** Create a new (visible, unlocked) layer; returns its id (0 on error). */
529
577
  addLayer(name: string): number;
@@ -577,4 +625,4 @@ declare class GigaPdfDoc {
577
625
  }): boolean;
578
626
  }
579
627
 
580
- export { type AnnotationInfo, type Box, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type LayerInfo, type LinkInfo, type OcrWord, type OutlineEntry, type PageInfo, type RadioOption, type SearchHit, type SignP12Options, type TextLine, type TextRunInfo };
628
+ export { type AnnotationInfo, type Box, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type RadioOption, type SearchHit, type SignP12Options, type TextLine, type TextRunInfo };
package/dist/index.js CHANGED
@@ -422,6 +422,12 @@ var GigaPdfDoc = class {
422
422
  return this.g._str((o) => this.ex().gp_ocr_text(this.h, page, scale, o));
423
423
  }
424
424
  // editing
425
+ /**
426
+ * Replace text run `index` on `page` with `text`. Font-aware: works with
427
+ * **any** font — a run set in an embedded Type0/Identity-H face (TrueType or
428
+ * OpenType-CFF) is re-encoded through that font's char→glyph map; base-14 and
429
+ * simple fonts use WinAnsi. Returns `false` if the run/page doesn't exist.
430
+ */
425
431
  replaceText(page, index, text) {
426
432
  return this.g._withStr(text, (p, l) => this.ex().gp_replace_text(this.h, page, index, p, l)) === 0;
427
433
  }
@@ -625,17 +631,33 @@ var GigaPdfDoc = class {
625
631
  renderPage(page, scale = 1) {
626
632
  return this.g._buffer((o) => this.ex().gp_render_page(this.h, page, scale, o));
627
633
  }
628
- // fonts — embed a downloaded TTF, then add real selectable text
629
- embedFont(family, ttf) {
634
+ // fonts — embed a downloaded font, then add real selectable text
635
+ /**
636
+ * Embed an outline font program as a Type0 font and return its object number
637
+ * (pass to {@link addText} / re-encoded by {@link replaceText}). Accepts
638
+ * **any** font file — glyf **TrueType** (`.ttf`) or **OpenType-CFF**
639
+ * (`.otf`/`OTTO`), flavour auto-detected — so `font` may be a Google Font the
640
+ * host fetched, an `.otf` you supply, or a face pulled out of a document with
641
+ * {@link extractFont}. Returns 0 on a malformed/unsupported program.
642
+ */
643
+ embedFont(family, font) {
630
644
  const b = enc.encode(family);
631
645
  const famPtr = this.g._toWasm(b);
632
646
  const obj = this.g._withBytes(
633
- ttf,
647
+ font,
634
648
  (p, l) => this.ex().gp_embed_font(this.h, famPtr, b.length, p, l)
635
649
  );
636
650
  this.g._free(famPtr, b.length);
637
651
  return obj;
638
652
  }
653
+ /**
654
+ * Draw real, selectable text at `(x, y)` (PDF points, origin bottom-left) in a
655
+ * font embedded with {@link embedFont} (`fontObj`). Works with **any** embedded
656
+ * face — glyf TrueType or OpenType-CFF — encoding each character through the
657
+ * font's char→glyph map (Identity-H, 2-byte glyph ids). `rgb` is packed
658
+ * `0xRRGGBB`; `rotationDeg` rotates CCW about `(x, y)`. For a built-in base-14
659
+ * family with no embedding, use {@link addStandardText}.
660
+ */
639
661
  addText(page, x, y, size, text, fontObj, rgb = 0, opacity = 1, rotationDeg = 0) {
640
662
  return this.g._withStr(
641
663
  text,
@@ -997,6 +1019,32 @@ var GigaPdfDoc = class {
997
1019
  addGotoLink(page, x0, y0, x1, y1, targetPage) {
998
1020
  return this.ex().gp_add_goto_link(this.h, page, x0, y0, x1, y1, targetPage) === 0;
999
1021
  }
1022
+ /**
1023
+ * Register a named destination `name` → `targetPage` (a whole-page `/Fit`
1024
+ * view) in the catalog. Links and bookmarks can then jump by name via
1025
+ * {@link addGotoLinkNamed}; because resolution goes through the catalog (not a
1026
+ * frozen page number), the anchor survives page extraction/split as long as
1027
+ * its page is kept. Re-using a `name` overwrites its target.
1028
+ */
1029
+ addNamedDest(name, targetPage) {
1030
+ return this.g._withStr(name, (p, l) => this.ex().gp_add_named_dest(this.h, p, l, targetPage)) === 0;
1031
+ }
1032
+ /** The catalog's named destinations as `{name, page}` pairs. */
1033
+ namedDests() {
1034
+ return this.g._json((o) => this.ex().gp_named_dests_json(this.h, o));
1035
+ }
1036
+ /**
1037
+ * Add an internal hyperlink over a rectangle that jumps to the named
1038
+ * destination `name` (define it with {@link addNamedDest}). Unlike
1039
+ * {@link addGotoLink} (an explicit page), this stores `/Dest /name`, keeping
1040
+ * cross-references intact through split/extract.
1041
+ */
1042
+ addGotoLinkNamed(page, x0, y0, x1, y1, name) {
1043
+ return this.g._withStr(
1044
+ name,
1045
+ (p, l) => this.ex().gp_add_goto_link_named(this.h, page, x0, y0, x1, y1, p, l)
1046
+ ) === 0;
1047
+ }
1000
1048
  // optional-content layers (calques): list + show/hide + lock/unlock + remove
1001
1049
  layers() {
1002
1050
  return this.g._json((o) => this.ex().gp_layers_json(this.h, o));