@qrcommunication/gigapdf-lib 0.67.0 → 0.69.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
@@ -365,6 +365,12 @@ declare class GigaPdfEngine {
365
365
  modelToHtml(model: GigaDocument): string;
366
366
  /** Raise a model to RTF (decoded UTF-8 string). */
367
367
  modelToRtf(model: GigaDocument): string;
368
+ /** Raise a model to Markdown (decoded UTF-8 string). */
369
+ modelToMarkdown(model: GigaDocument): string;
370
+ /** Raise a model to CSV (decoded UTF-8 string). */
371
+ modelToCsv(model: GigaDocument): string;
372
+ /** Raise a model to an EPUB e-book (`.epub`). */
373
+ modelToEpub(model: GigaDocument): Uint8Array;
368
374
  }
369
375
  /** A Google font the HTML engine needs (resolved from the catalogue). */
370
376
  interface HtmlFontRequest {
@@ -1481,6 +1487,35 @@ declare class GigaPdfDoc {
1481
1487
  strokeAlpha?: number;
1482
1488
  dash?: number[];
1483
1489
  }): boolean;
1490
+ /**
1491
+ * Re-style **sub-ranges** of text run `index` on `page` in place — the
1492
+ * by-character-run companion of {@link setPathStyle}. Each span sets the style
1493
+ * of the `[start, end)` UTF-16 slice of the run's *decoded* text (bold / italic
1494
+ * / underline / strike / colour / size); the run is split so the rest keeps its
1495
+ * original style and **positioning is preserved** (the original glyph codes,
1496
+ * including `TJ` kerning, are sliced and re-emitted — never re-encoded — and
1497
+ * each styled slice is wrapped in `q … Q`). Spans may be given in any order and
1498
+ * are clamped to the run's length.
1499
+ *
1500
+ * Notes on each field: `color` is `[r,g,b]` in `0..=1` (text fill); `sizePt`
1501
+ * rescales the slice's font in the run's own text scale; `bold` is faux-bold
1502
+ * (fill+stroke render mode) when no bold variant font is wired; `italic` is a
1503
+ * no-op without an italic/oblique variant (a stream edit can't shear glyphs
1504
+ * without disturbing advances); `underline`/`strike` draw a thin rule in page
1505
+ * space. Returns `false` when `index` does not resolve to a top-level text run
1506
+ * (e.g. it addresses form-XObject text), like {@link setPathStyle} for a
1507
+ * non-matching element.
1508
+ */
1509
+ setTextRunStyle(page: number, index: number, spans: Array<{
1510
+ start: number;
1511
+ end: number;
1512
+ color?: [number, number, number];
1513
+ sizePt?: number;
1514
+ bold?: boolean;
1515
+ italic?: boolean;
1516
+ underline?: boolean;
1517
+ strike?: boolean;
1518
+ }>): boolean;
1484
1519
  /**
1485
1520
  * Set a constant opacity on element `index` on `page` — text, image **or**
1486
1521
  * shape — by registering an `/ExtGState` (`/ca` = `/CA` = `fillAlpha`, clamped
@@ -1532,6 +1567,30 @@ declare class GigaPdfDoc {
1532
1567
  * user space. PNG alpha is honoured; `opacity` (0..1) sets an overall alpha.
1533
1568
  */
1534
1569
  addImage(page: number, data: Uint8Array, x: number, y: number, w: number, h: number, opacity?: number): boolean;
1570
+ /**
1571
+ * Stamp an **image watermark** across pages from raw image bytes. Accepts the
1572
+ * same five formats the engine decodes — **PNG, JPEG, WebP, GIF, AVIF**. The
1573
+ * image is embedded **once** and referenced on every target page.
1574
+ *
1575
+ * `opts.pages` is a list of 1-based page numbers; omit it (or pass `[]`) to
1576
+ * stamp every page. `opts.anchor` positions the image (`'center'` default, or a
1577
+ * corner) and `opts.offsetX`/`offsetY` nudge it (in points; in `tile` mode they
1578
+ * become the gaps between tiles). `opts.width`/`height` set the target size in
1579
+ * points (height keeps the source aspect ratio when omitted). `opts.rotationDeg`
1580
+ * rotates about the image centre and `opts.opacity` (0–1) sets the alpha.
1581
+ * Returns `false` if the image can't be decoded.
1582
+ */
1583
+ addImageWatermark(data: Uint8Array, opts?: {
1584
+ pages?: number[];
1585
+ anchor?: 'center' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
1586
+ offsetX?: number;
1587
+ offsetY?: number;
1588
+ width?: number;
1589
+ height?: number;
1590
+ rotationDeg?: number;
1591
+ opacity?: number;
1592
+ tile?: boolean;
1593
+ }): boolean;
1535
1594
  /**
1536
1595
  * Draw SVG markup on a page as **native vector paths** (crisp at any zoom, not
1537
1596
  * rasterized), fitting its `viewBox` into the box `(x, y, w, h)` in PDF points
package/dist/index.d.ts CHANGED
@@ -365,6 +365,12 @@ declare class GigaPdfEngine {
365
365
  modelToHtml(model: GigaDocument): string;
366
366
  /** Raise a model to RTF (decoded UTF-8 string). */
367
367
  modelToRtf(model: GigaDocument): string;
368
+ /** Raise a model to Markdown (decoded UTF-8 string). */
369
+ modelToMarkdown(model: GigaDocument): string;
370
+ /** Raise a model to CSV (decoded UTF-8 string). */
371
+ modelToCsv(model: GigaDocument): string;
372
+ /** Raise a model to an EPUB e-book (`.epub`). */
373
+ modelToEpub(model: GigaDocument): Uint8Array;
368
374
  }
369
375
  /** A Google font the HTML engine needs (resolved from the catalogue). */
370
376
  interface HtmlFontRequest {
@@ -1481,6 +1487,35 @@ declare class GigaPdfDoc {
1481
1487
  strokeAlpha?: number;
1482
1488
  dash?: number[];
1483
1489
  }): boolean;
1490
+ /**
1491
+ * Re-style **sub-ranges** of text run `index` on `page` in place — the
1492
+ * by-character-run companion of {@link setPathStyle}. Each span sets the style
1493
+ * of the `[start, end)` UTF-16 slice of the run's *decoded* text (bold / italic
1494
+ * / underline / strike / colour / size); the run is split so the rest keeps its
1495
+ * original style and **positioning is preserved** (the original glyph codes,
1496
+ * including `TJ` kerning, are sliced and re-emitted — never re-encoded — and
1497
+ * each styled slice is wrapped in `q … Q`). Spans may be given in any order and
1498
+ * are clamped to the run's length.
1499
+ *
1500
+ * Notes on each field: `color` is `[r,g,b]` in `0..=1` (text fill); `sizePt`
1501
+ * rescales the slice's font in the run's own text scale; `bold` is faux-bold
1502
+ * (fill+stroke render mode) when no bold variant font is wired; `italic` is a
1503
+ * no-op without an italic/oblique variant (a stream edit can't shear glyphs
1504
+ * without disturbing advances); `underline`/`strike` draw a thin rule in page
1505
+ * space. Returns `false` when `index` does not resolve to a top-level text run
1506
+ * (e.g. it addresses form-XObject text), like {@link setPathStyle} for a
1507
+ * non-matching element.
1508
+ */
1509
+ setTextRunStyle(page: number, index: number, spans: Array<{
1510
+ start: number;
1511
+ end: number;
1512
+ color?: [number, number, number];
1513
+ sizePt?: number;
1514
+ bold?: boolean;
1515
+ italic?: boolean;
1516
+ underline?: boolean;
1517
+ strike?: boolean;
1518
+ }>): boolean;
1484
1519
  /**
1485
1520
  * Set a constant opacity on element `index` on `page` — text, image **or**
1486
1521
  * shape — by registering an `/ExtGState` (`/ca` = `/CA` = `fillAlpha`, clamped
@@ -1532,6 +1567,30 @@ declare class GigaPdfDoc {
1532
1567
  * user space. PNG alpha is honoured; `opacity` (0..1) sets an overall alpha.
1533
1568
  */
1534
1569
  addImage(page: number, data: Uint8Array, x: number, y: number, w: number, h: number, opacity?: number): boolean;
1570
+ /**
1571
+ * Stamp an **image watermark** across pages from raw image bytes. Accepts the
1572
+ * same five formats the engine decodes — **PNG, JPEG, WebP, GIF, AVIF**. The
1573
+ * image is embedded **once** and referenced on every target page.
1574
+ *
1575
+ * `opts.pages` is a list of 1-based page numbers; omit it (or pass `[]`) to
1576
+ * stamp every page. `opts.anchor` positions the image (`'center'` default, or a
1577
+ * corner) and `opts.offsetX`/`offsetY` nudge it (in points; in `tile` mode they
1578
+ * become the gaps between tiles). `opts.width`/`height` set the target size in
1579
+ * points (height keeps the source aspect ratio when omitted). `opts.rotationDeg`
1580
+ * rotates about the image centre and `opts.opacity` (0–1) sets the alpha.
1581
+ * Returns `false` if the image can't be decoded.
1582
+ */
1583
+ addImageWatermark(data: Uint8Array, opts?: {
1584
+ pages?: number[];
1585
+ anchor?: 'center' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
1586
+ offsetX?: number;
1587
+ offsetY?: number;
1588
+ width?: number;
1589
+ height?: number;
1590
+ rotationDeg?: number;
1591
+ opacity?: number;
1592
+ tile?: boolean;
1593
+ }): boolean;
1535
1594
  /**
1536
1595
  * Draw SVG markup on a page as **native vector paths** (crisp at any zoom, not
1537
1596
  * rasterized), fitting its `viewBox` into the box `(x, y, w, h)` in PDF points
package/dist/index.js CHANGED
@@ -806,6 +806,27 @@ var GigaPdfEngine = class _GigaPdfEngine {
806
806
  (p, l) => this._str((o) => this.ex.gp_model_to_rtf(p, l, o))
807
807
  );
808
808
  }
809
+ /** Raise a model to Markdown (decoded UTF-8 string). */
810
+ modelToMarkdown(model) {
811
+ return this._withStr(
812
+ JSON.stringify(model),
813
+ (p, l) => this._str((o) => this.ex.gp_model_to_md(p, l, o))
814
+ );
815
+ }
816
+ /** Raise a model to CSV (decoded UTF-8 string). */
817
+ modelToCsv(model) {
818
+ return this._withStr(
819
+ JSON.stringify(model),
820
+ (p, l) => this._str((o) => this.ex.gp_model_to_csv(p, l, o))
821
+ );
822
+ }
823
+ /** Raise a model to an EPUB e-book (`.epub`). */
824
+ modelToEpub(model) {
825
+ return this._withStr(
826
+ JSON.stringify(model),
827
+ (p, l) => this._buffer((o) => this.ex.gp_model_to_epub(p, l, o))
828
+ );
829
+ }
809
830
  };
810
831
  function packHtmlResources(resources) {
811
832
  let size = 4;
@@ -1037,6 +1058,31 @@ var GigaPdfDoc = class {
1037
1058
  (p, l) => this.ex().gp_set_path_style_json(this.h, page, index, p, l)
1038
1059
  ) === 0;
1039
1060
  }
1061
+ /**
1062
+ * Re-style **sub-ranges** of text run `index` on `page` in place — the
1063
+ * by-character-run companion of {@link setPathStyle}. Each span sets the style
1064
+ * of the `[start, end)` UTF-16 slice of the run's *decoded* text (bold / italic
1065
+ * / underline / strike / colour / size); the run is split so the rest keeps its
1066
+ * original style and **positioning is preserved** (the original glyph codes,
1067
+ * including `TJ` kerning, are sliced and re-emitted — never re-encoded — and
1068
+ * each styled slice is wrapped in `q … Q`). Spans may be given in any order and
1069
+ * are clamped to the run's length.
1070
+ *
1071
+ * Notes on each field: `color` is `[r,g,b]` in `0..=1` (text fill); `sizePt`
1072
+ * rescales the slice's font in the run's own text scale; `bold` is faux-bold
1073
+ * (fill+stroke render mode) when no bold variant font is wired; `italic` is a
1074
+ * no-op without an italic/oblique variant (a stream edit can't shear glyphs
1075
+ * without disturbing advances); `underline`/`strike` draw a thin rule in page
1076
+ * space. Returns `false` when `index` does not resolve to a top-level text run
1077
+ * (e.g. it addresses form-XObject text), like {@link setPathStyle} for a
1078
+ * non-matching element.
1079
+ */
1080
+ setTextRunStyle(page, index, spans) {
1081
+ return this.g._withStr(
1082
+ JSON.stringify(spans),
1083
+ (p, l) => this.ex().gp_set_text_run_style_json(this.h, page, index, p, l)
1084
+ ) === 0;
1085
+ }
1040
1086
  /**
1041
1087
  * Set a constant opacity on element `index` on `page` — text, image **or**
1042
1088
  * shape — by registering an `/ExtGState` (`/ca` = `/CA` = `fillAlpha`, clamped
@@ -1168,6 +1214,49 @@ var GigaPdfDoc = class {
1168
1214
  (p, l) => this.ex().gp_add_image(this.h, page, p, l, x, y, w, h, opacity)
1169
1215
  ) === 0;
1170
1216
  }
1217
+ /**
1218
+ * Stamp an **image watermark** across pages from raw image bytes. Accepts the
1219
+ * same five formats the engine decodes — **PNG, JPEG, WebP, GIF, AVIF**. The
1220
+ * image is embedded **once** and referenced on every target page.
1221
+ *
1222
+ * `opts.pages` is a list of 1-based page numbers; omit it (or pass `[]`) to
1223
+ * stamp every page. `opts.anchor` positions the image (`'center'` default, or a
1224
+ * corner) and `opts.offsetX`/`offsetY` nudge it (in points; in `tile` mode they
1225
+ * become the gaps between tiles). `opts.width`/`height` set the target size in
1226
+ * points (height keeps the source aspect ratio when omitted). `opts.rotationDeg`
1227
+ * rotates about the image centre and `opts.opacity` (0–1) sets the alpha.
1228
+ * Returns `false` if the image can't be decoded.
1229
+ */
1230
+ addImageWatermark(data, opts = {}) {
1231
+ const anchorTag = {
1232
+ center: 0,
1233
+ "top-left": 1,
1234
+ "top-right": 2,
1235
+ "bottom-left": 3,
1236
+ "bottom-right": 4
1237
+ }[opts.anchor ?? "center"];
1238
+ const pages = opts.pages ?? [];
1239
+ const call = (pp, pc) => this.g._withBytes(
1240
+ data,
1241
+ (p, l) => this.ex().gp_add_image_watermark(
1242
+ this.h,
1243
+ p,
1244
+ l,
1245
+ pp,
1246
+ pc,
1247
+ anchorTag,
1248
+ opts.offsetX ?? 0,
1249
+ opts.offsetY ?? 0,
1250
+ opts.width ?? 0,
1251
+ opts.height ?? 0,
1252
+ opts.rotationDeg ?? 0,
1253
+ opts.opacity ?? 0.25,
1254
+ opts.tile ? 1 : 0
1255
+ )
1256
+ );
1257
+ const rc = pages.length === 0 ? call(0, 0) : this.g._withU32(pages, (pp, pc) => call(pp, pc));
1258
+ return rc === 0;
1259
+ }
1171
1260
  /**
1172
1261
  * Draw SVG markup on a page as **native vector paths** (crisp at any zoom, not
1173
1262
  * rasterized), fitting its `viewBox` into the box `(x, y, w, h)` in PDF points