@qrcommunication/gigapdf-lib 0.104.0 → 0.105.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
@@ -92,6 +92,12 @@ declare class GigaPdfEngine {
92
92
  * "unrecognized" must stay distinct.
93
93
  */
94
94
  _jsonOrNull<T = unknown>(call: (outLenPtr: number) => number): T | null;
95
+ /**
96
+ * Like {@link _str} but distinguishes a **null** result (the export returned a
97
+ * null pointer — e.g. an `Option::None`) from a present-but-empty string.
98
+ * Returns `null` only for the null pointer; otherwise the decoded string.
99
+ */
100
+ _strOrNull(call: (outLenPtr: number) => number): string | null;
95
101
  /**
96
102
  * Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
97
103
  * works identically in Node and the browser with no dependency (used to turn
@@ -1853,6 +1859,93 @@ interface HeaderFooterSpec {
1853
1859
  /** Band height from the page edge, in points (default `36`). */
1854
1860
  bandHeight?: number;
1855
1861
  }
1862
+ /** Horizontal anchor of a rich {@link HFItem} within the printable width. */
1863
+ type HFAlign = HeaderFooterAlign;
1864
+ /**
1865
+ * One drawable element of a rich running header/footer band: a line of **text**
1866
+ * or a raster **image** (a discriminated union on `type`). Anchored within the
1867
+ * printable width by `anchor`, then nudged `(dx, dy)` points in PDF axes
1868
+ * (`+dx` → right, `+dy` → up).
1869
+ */
1870
+ type HFItem = {
1871
+ type: "text";
1872
+ /** Horizontal anchor (default `"left"`). */
1873
+ anchor?: HFAlign;
1874
+ /** Horizontal nudge, points (default `0`). */
1875
+ dx?: number;
1876
+ /** Vertical nudge, points (default `0`). */
1877
+ dy?: number;
1878
+ /**
1879
+ * Template text — may contain `{{page}}`, `{{pages}}`, `{{date}}` and
1880
+ * `{{title}}`, substituted at bake time.
1881
+ */
1882
+ text: string;
1883
+ /**
1884
+ * An embedded-font object id (from {@link GigaPdfDoc.embedFont}); omit/`null`
1885
+ * to use the engine's bundled OFL face (a real embedded font, never base-14).
1886
+ */
1887
+ fontRef?: number | null;
1888
+ /** Font size, points (default `10`). */
1889
+ size?: number;
1890
+ /** RGB fill colour, `0..255` per channel (default black `[0,0,0]`). */
1891
+ color?: [number, number, number];
1892
+ /** Bold hint (carried with the def; honoured only by a bold `fontRef`). */
1893
+ bold?: boolean;
1894
+ /** Italic hint (carried with the def; honoured only by an italic `fontRef`). */
1895
+ italic?: boolean;
1896
+ } | {
1897
+ type: "image";
1898
+ /** Horizontal anchor (default `"left"`). */
1899
+ anchor?: HFAlign;
1900
+ /** Horizontal nudge, points (default `0`). */
1901
+ dx?: number;
1902
+ /** Vertical nudge, points (default `0`). */
1903
+ dy?: number;
1904
+ /** Drawn width, points. */
1905
+ w: number;
1906
+ /** Drawn height, points. */
1907
+ h: number;
1908
+ /** Key into the `images` map passed to {@link GigaPdfDoc.setRunningHeaderFooter}. */
1909
+ imageId: number;
1910
+ /** Fill opacity `0..1` (default `1`). */
1911
+ opacity?: number;
1912
+ };
1913
+ /** The header and footer item lists of one running-H/F {@link RunningHeaderFooter} zone. */
1914
+ interface HFZone {
1915
+ /** Items drawn in the top (header) band. */
1916
+ header: HFItem[];
1917
+ /** Items drawn in the bottom (footer) band. */
1918
+ footer: HFItem[];
1919
+ }
1920
+ /**
1921
+ * A rich, Word-like running header/footer **definition** (see
1922
+ * {@link GigaPdfDoc.setRunningHeaderFooter}). The definition is the source of
1923
+ * truth (stored in the editor-meta sidecar); the bake regenerates the visible
1924
+ * `/GPHF` band from it.
1925
+ *
1926
+ * Zone selection per 1-based page: page 1 → `firstPage` when `differentFirstPage`
1927
+ * (else `default`); otherwise, when `differentOddEven`, even pages → `evenPage`
1928
+ * and odd pages → `oddPage` (each falling back to `default` when omitted);
1929
+ * otherwise `default` everywhere.
1930
+ */
1931
+ interface RunningHeaderFooter {
1932
+ /** The zone every page not overridden by a more specific zone uses. */
1933
+ default: HFZone;
1934
+ /** First-page override (used when `differentFirstPage`). */
1935
+ firstPage?: HFZone | null;
1936
+ /** Even-page override (used when `differentOddEven`). */
1937
+ evenPage?: HFZone | null;
1938
+ /** Odd-page override (used when `differentOddEven`). */
1939
+ oddPage?: HFZone | null;
1940
+ /** Give page 1 its own `firstPage` zone (default `false`). */
1941
+ differentFirstPage?: boolean;
1942
+ /** Give even/odd pages their own `evenPage`/`oddPage` zones (default `false`). */
1943
+ differentOddEven?: boolean;
1944
+ /** Header band height (distance from the top edge to the baseline), points (default `36`). */
1945
+ headerBand?: number;
1946
+ /** Footer band height (distance from the bottom edge to the baseline), points (default `36`). */
1947
+ footerBand?: number;
1948
+ }
1856
1949
  /** One colour stop of a {@link GradientSpec}. */
1857
1950
  interface GradientStop {
1858
1951
  /** Position along the gradient axis, `0`…`1`. */
@@ -2422,6 +2515,34 @@ declare class GigaPdfDoc {
2422
2515
  * — a real, visible margin change. Returns `true` on success.
2423
2516
  */
2424
2517
  setPageMargins(page: number, m: PageMargins): boolean;
2518
+ /**
2519
+ * Store an **opaque** JSON string as the document's GigaPDF editor-metadata
2520
+ * sidecar — private editor state that travels with the PDF (catalog
2521
+ * `/GigaPDF /EditorMeta`, a FlateDecode-compressed stream). It is ignored by
2522
+ * every standard PDF reader and the round-trip survives save/open. Pass a JSON
2523
+ * **object** if you also use {@link setEditorMargins} (which read-modify-writes
2524
+ * that object's `margins` key). Returns `true` on success.
2525
+ */
2526
+ setEditorMeta(json: string): boolean;
2527
+ /**
2528
+ * The document's GigaPDF editor-metadata sidecar string (set by
2529
+ * {@link setEditorMeta}), or `null` when the document carries none.
2530
+ */
2531
+ editorMeta(): string | null;
2532
+ /**
2533
+ * Record the editor's per-page **display** margins (points) in the
2534
+ * editor-metadata sidecar (under `margins`, keyed by page) **without touching
2535
+ * `/CropBox` or `/MediaBox`** — distinct from {@link setPageMargins}, which
2536
+ * performs a real visible recrop. Any other host keys in the sidecar are
2537
+ * preserved. Returns `true` on success.
2538
+ */
2539
+ setEditorMargins(page: number, m: PageMargins): boolean;
2540
+ /**
2541
+ * The editor's per-page display margins (points) recorded for `page` by
2542
+ * {@link setEditorMargins}, or `null` when none were stored. Reads only the
2543
+ * sidecar — never `/CropBox`.
2544
+ */
2545
+ editorMargins(page: number): PageMargins | null;
2425
2546
  /**
2426
2547
  * All five page boundary boxes (`media`/`crop`/`bleed`/`trim`/`art`) for the
2427
2548
  * 1-based `page`, each as `[x0, y0, x1, y1]` in points, with ISO 32000-1
@@ -2521,6 +2642,50 @@ declare class GigaPdfDoc {
2521
2642
  header: HeaderFooterSpec | null;
2522
2643
  footer: HeaderFooterSpec | null;
2523
2644
  };
2645
+ /**
2646
+ * Bake a **rich**, Word-like running header/footer from a {@link RunningHeaderFooter}
2647
+ * `def` (the source of truth — stored in the editor-meta sidecar, its visible
2648
+ * `/GPHF` band regenerated on every page). Text is set in an embedded font
2649
+ * (each item's `fontRef`, else the bundled OFL face — never base-14) and images
2650
+ * via the same path as {@link addImage}; both live inside the `/GPHF` span, so
2651
+ * they are excluded from {@link elements}/{@link textRuns} and masked by
2652
+ * {@link renderPageExcludingMarkedContent}. Idempotent (re-baking replaces the
2653
+ * prior band).
2654
+ *
2655
+ * `opts.date` is the bake date for `{{date}}` (the engine is clockless — pass
2656
+ * e.g. `new Date().toISOString().slice(0, 10)`); omit to fall back to the
2657
+ * document's `/Info` date. `opts.images` supplies the pixels each
2658
+ * `HFItem` of `type: "image"` references by `imageId` — an iterable of
2659
+ * `[imageId, bytes]` (a `Map<number, Uint8Array>` works directly); an image
2660
+ * whose id is absent is skipped. Returns `true` on success.
2661
+ *
2662
+ * @example
2663
+ * doc.setRunningHeaderFooter(
2664
+ * {
2665
+ * default: {
2666
+ * header: [{ type: "image", imageId: 1, w: 80, h: 24, anchor: "left" }],
2667
+ * footer: [{ type: "text", text: "{{title}} — {{page}}/{{pages}}", anchor: "center" }],
2668
+ * },
2669
+ * firstPage: { header: [], footer: [] }, // blank cover
2670
+ * differentFirstPage: true,
2671
+ * differentOddEven: true,
2672
+ * evenPage: { header: [{ type: "text", text: "{{page}}", anchor: "left" }], footer: [] },
2673
+ * oddPage: { header: [{ type: "text", text: "{{page}}", anchor: "right" }], footer: [] },
2674
+ * },
2675
+ * { date: new Date().toISOString().slice(0, 10), images: new Map([[1, logoPng]]) }
2676
+ * );
2677
+ */
2678
+ setRunningHeaderFooter(def: RunningHeaderFooter, opts?: {
2679
+ date?: string;
2680
+ images?: Iterable<[number, Uint8Array]>;
2681
+ }): boolean;
2682
+ /**
2683
+ * The rich {@link RunningHeaderFooter} definition recorded by
2684
+ * {@link setRunningHeaderFooter} (read from the editor-meta sidecar — the
2685
+ * source of truth), or a minimal one reconstructed from a legacy flat
2686
+ * {@link setHeader}/{@link setFooter} bake, or `null` when neither is present.
2687
+ */
2688
+ runningHeaderFooter(): RunningHeaderFooter | null;
2524
2689
  renderPage(page: number, scale?: number): Uint8Array;
2525
2690
  /**
2526
2691
  * Rasterize a page to a PNG **without the page content stream's text** — glyphs
@@ -2545,6 +2710,18 @@ declare class GigaPdfDoc {
2545
2710
  * page; unknown indices are ignored.
2546
2711
  */
2547
2712
  renderPageExcluding(page: number, indices: number[], scale?: number): Uint8Array;
2713
+ /**
2714
+ * Rasterize a page to a PNG **excluding the ops inside a baked marked-content
2715
+ * span** named `marker` — and, when `skipText` is true, the page's text too — in
2716
+ * a **single** raster pass. For `marker = "GPHF"` (the default) this drops the
2717
+ * baked running header/footer band: the extraction views ({@link elements},
2718
+ * {@link textRuns}) already omit that band (it is never editable body content),
2719
+ * and this render omits it from the picture so it cannot double against an
2720
+ * editable overlay. With `skipText = true` it is the editor's text-free display
2721
+ * background minus the band; with `skipText = false`, the full page minus the
2722
+ * band. Like {@link renderPageNoText}, form-field widget appearances are omitted.
2723
+ */
2724
+ renderPageExcludingMarkedContent(page: number, scale?: number, skipText?: boolean, marker?: string): Uint8Array;
2548
2725
  /**
2549
2726
  * Embed an outline font program as a Type0 font and return its object number
2550
2727
  * (pass to {@link addText} / re-encoded by {@link replaceText}). Accepts
@@ -3176,4 +3353,4 @@ declare class GigaPdfDoc {
3176
3353
  regenerateFieldAppearance(name: string): boolean;
3177
3354
  }
3178
3355
 
3179
- export { type Action, type AfRelationship, type AnnotationInfo, type Attachment, type AttachmentOptions, type Bookmark, type Box, type CollectionConfig, type CollectionField, type CollectionFieldSubtype, type CollectionItem, type CollectionView, type Color, type DecodedImage, type Destination, type DocumentJavascript, type DocumentLanguage, type Element, type EmbeddedFont, type Exports, type FieldInfo, type FieldKind, type FieldStyle, type FileAttachmentIcon, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type GradientSpec, type GradientStop, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type InfoFields, type LayerInfo, type LinkInfo, type MergePart, type ModelOp, type NamedDest, type OutlineEntry, PAGE_BOX_KINDS, PAGE_TRANSITION_STYLES, type PageBoxKind, type PageBoxes, type PageInfo, type PageLabelRange, type PageLabelStyle, type PageLayout, type PageMargins, type PageMode, type PageTransition, type PageTransitionDimension, type PageTransitionDirection, type PageTransitionMotion, type PageTransitionStyle, type PathSegment, type PdfPermissions, type PdfVersion, type RadioOption, type SearchHit, type SignLtvOptions, type SignP12Options, type SignTsaOptions, type SignatureInfo, type SignatureReport, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type ViewerPreferences, type XlsxSheet, defaultCrlGet, defaultOcspPost, defaultTsaPost };
3356
+ export { type Action, type AfRelationship, type AnnotationInfo, type Attachment, type AttachmentOptions, type Bookmark, type Box, type CollectionConfig, type CollectionField, type CollectionFieldSubtype, type CollectionItem, type CollectionView, type Color, type DecodedImage, type Destination, type DocumentJavascript, type DocumentLanguage, type Element, type EmbeddedFont, type Exports, type FieldInfo, type FieldKind, type FieldStyle, type FileAttachmentIcon, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type GradientSpec, type GradientStop, type HFAlign, type HFItem, type HFZone, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type InfoFields, type LayerInfo, type LinkInfo, type MergePart, type ModelOp, type NamedDest, type OutlineEntry, PAGE_BOX_KINDS, PAGE_TRANSITION_STYLES, type PageBoxKind, type PageBoxes, type PageInfo, type PageLabelRange, type PageLabelStyle, type PageLayout, type PageMargins, type PageMode, type PageTransition, type PageTransitionDimension, type PageTransitionDirection, type PageTransitionMotion, type PageTransitionStyle, type PathSegment, type PdfPermissions, type PdfVersion, type RadioOption, type RunningHeaderFooter, type SearchHit, type SignLtvOptions, type SignP12Options, type SignTsaOptions, type SignatureInfo, type SignatureReport, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type ViewerPreferences, type XlsxSheet, defaultCrlGet, defaultOcspPost, defaultTsaPost };
package/dist/index.d.ts CHANGED
@@ -92,6 +92,12 @@ declare class GigaPdfEngine {
92
92
  * "unrecognized" must stay distinct.
93
93
  */
94
94
  _jsonOrNull<T = unknown>(call: (outLenPtr: number) => number): T | null;
95
+ /**
96
+ * Like {@link _str} but distinguishes a **null** result (the export returned a
97
+ * null pointer — e.g. an `Option::None`) from a present-but-empty string.
98
+ * Returns `null` only for the null pointer; otherwise the decoded string.
99
+ */
100
+ _strOrNull(call: (outLenPtr: number) => number): string | null;
95
101
  /**
96
102
  * Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
97
103
  * works identically in Node and the browser with no dependency (used to turn
@@ -1853,6 +1859,93 @@ interface HeaderFooterSpec {
1853
1859
  /** Band height from the page edge, in points (default `36`). */
1854
1860
  bandHeight?: number;
1855
1861
  }
1862
+ /** Horizontal anchor of a rich {@link HFItem} within the printable width. */
1863
+ type HFAlign = HeaderFooterAlign;
1864
+ /**
1865
+ * One drawable element of a rich running header/footer band: a line of **text**
1866
+ * or a raster **image** (a discriminated union on `type`). Anchored within the
1867
+ * printable width by `anchor`, then nudged `(dx, dy)` points in PDF axes
1868
+ * (`+dx` → right, `+dy` → up).
1869
+ */
1870
+ type HFItem = {
1871
+ type: "text";
1872
+ /** Horizontal anchor (default `"left"`). */
1873
+ anchor?: HFAlign;
1874
+ /** Horizontal nudge, points (default `0`). */
1875
+ dx?: number;
1876
+ /** Vertical nudge, points (default `0`). */
1877
+ dy?: number;
1878
+ /**
1879
+ * Template text — may contain `{{page}}`, `{{pages}}`, `{{date}}` and
1880
+ * `{{title}}`, substituted at bake time.
1881
+ */
1882
+ text: string;
1883
+ /**
1884
+ * An embedded-font object id (from {@link GigaPdfDoc.embedFont}); omit/`null`
1885
+ * to use the engine's bundled OFL face (a real embedded font, never base-14).
1886
+ */
1887
+ fontRef?: number | null;
1888
+ /** Font size, points (default `10`). */
1889
+ size?: number;
1890
+ /** RGB fill colour, `0..255` per channel (default black `[0,0,0]`). */
1891
+ color?: [number, number, number];
1892
+ /** Bold hint (carried with the def; honoured only by a bold `fontRef`). */
1893
+ bold?: boolean;
1894
+ /** Italic hint (carried with the def; honoured only by an italic `fontRef`). */
1895
+ italic?: boolean;
1896
+ } | {
1897
+ type: "image";
1898
+ /** Horizontal anchor (default `"left"`). */
1899
+ anchor?: HFAlign;
1900
+ /** Horizontal nudge, points (default `0`). */
1901
+ dx?: number;
1902
+ /** Vertical nudge, points (default `0`). */
1903
+ dy?: number;
1904
+ /** Drawn width, points. */
1905
+ w: number;
1906
+ /** Drawn height, points. */
1907
+ h: number;
1908
+ /** Key into the `images` map passed to {@link GigaPdfDoc.setRunningHeaderFooter}. */
1909
+ imageId: number;
1910
+ /** Fill opacity `0..1` (default `1`). */
1911
+ opacity?: number;
1912
+ };
1913
+ /** The header and footer item lists of one running-H/F {@link RunningHeaderFooter} zone. */
1914
+ interface HFZone {
1915
+ /** Items drawn in the top (header) band. */
1916
+ header: HFItem[];
1917
+ /** Items drawn in the bottom (footer) band. */
1918
+ footer: HFItem[];
1919
+ }
1920
+ /**
1921
+ * A rich, Word-like running header/footer **definition** (see
1922
+ * {@link GigaPdfDoc.setRunningHeaderFooter}). The definition is the source of
1923
+ * truth (stored in the editor-meta sidecar); the bake regenerates the visible
1924
+ * `/GPHF` band from it.
1925
+ *
1926
+ * Zone selection per 1-based page: page 1 → `firstPage` when `differentFirstPage`
1927
+ * (else `default`); otherwise, when `differentOddEven`, even pages → `evenPage`
1928
+ * and odd pages → `oddPage` (each falling back to `default` when omitted);
1929
+ * otherwise `default` everywhere.
1930
+ */
1931
+ interface RunningHeaderFooter {
1932
+ /** The zone every page not overridden by a more specific zone uses. */
1933
+ default: HFZone;
1934
+ /** First-page override (used when `differentFirstPage`). */
1935
+ firstPage?: HFZone | null;
1936
+ /** Even-page override (used when `differentOddEven`). */
1937
+ evenPage?: HFZone | null;
1938
+ /** Odd-page override (used when `differentOddEven`). */
1939
+ oddPage?: HFZone | null;
1940
+ /** Give page 1 its own `firstPage` zone (default `false`). */
1941
+ differentFirstPage?: boolean;
1942
+ /** Give even/odd pages their own `evenPage`/`oddPage` zones (default `false`). */
1943
+ differentOddEven?: boolean;
1944
+ /** Header band height (distance from the top edge to the baseline), points (default `36`). */
1945
+ headerBand?: number;
1946
+ /** Footer band height (distance from the bottom edge to the baseline), points (default `36`). */
1947
+ footerBand?: number;
1948
+ }
1856
1949
  /** One colour stop of a {@link GradientSpec}. */
1857
1950
  interface GradientStop {
1858
1951
  /** Position along the gradient axis, `0`…`1`. */
@@ -2422,6 +2515,34 @@ declare class GigaPdfDoc {
2422
2515
  * — a real, visible margin change. Returns `true` on success.
2423
2516
  */
2424
2517
  setPageMargins(page: number, m: PageMargins): boolean;
2518
+ /**
2519
+ * Store an **opaque** JSON string as the document's GigaPDF editor-metadata
2520
+ * sidecar — private editor state that travels with the PDF (catalog
2521
+ * `/GigaPDF /EditorMeta`, a FlateDecode-compressed stream). It is ignored by
2522
+ * every standard PDF reader and the round-trip survives save/open. Pass a JSON
2523
+ * **object** if you also use {@link setEditorMargins} (which read-modify-writes
2524
+ * that object's `margins` key). Returns `true` on success.
2525
+ */
2526
+ setEditorMeta(json: string): boolean;
2527
+ /**
2528
+ * The document's GigaPDF editor-metadata sidecar string (set by
2529
+ * {@link setEditorMeta}), or `null` when the document carries none.
2530
+ */
2531
+ editorMeta(): string | null;
2532
+ /**
2533
+ * Record the editor's per-page **display** margins (points) in the
2534
+ * editor-metadata sidecar (under `margins`, keyed by page) **without touching
2535
+ * `/CropBox` or `/MediaBox`** — distinct from {@link setPageMargins}, which
2536
+ * performs a real visible recrop. Any other host keys in the sidecar are
2537
+ * preserved. Returns `true` on success.
2538
+ */
2539
+ setEditorMargins(page: number, m: PageMargins): boolean;
2540
+ /**
2541
+ * The editor's per-page display margins (points) recorded for `page` by
2542
+ * {@link setEditorMargins}, or `null` when none were stored. Reads only the
2543
+ * sidecar — never `/CropBox`.
2544
+ */
2545
+ editorMargins(page: number): PageMargins | null;
2425
2546
  /**
2426
2547
  * All five page boundary boxes (`media`/`crop`/`bleed`/`trim`/`art`) for the
2427
2548
  * 1-based `page`, each as `[x0, y0, x1, y1]` in points, with ISO 32000-1
@@ -2521,6 +2642,50 @@ declare class GigaPdfDoc {
2521
2642
  header: HeaderFooterSpec | null;
2522
2643
  footer: HeaderFooterSpec | null;
2523
2644
  };
2645
+ /**
2646
+ * Bake a **rich**, Word-like running header/footer from a {@link RunningHeaderFooter}
2647
+ * `def` (the source of truth — stored in the editor-meta sidecar, its visible
2648
+ * `/GPHF` band regenerated on every page). Text is set in an embedded font
2649
+ * (each item's `fontRef`, else the bundled OFL face — never base-14) and images
2650
+ * via the same path as {@link addImage}; both live inside the `/GPHF` span, so
2651
+ * they are excluded from {@link elements}/{@link textRuns} and masked by
2652
+ * {@link renderPageExcludingMarkedContent}. Idempotent (re-baking replaces the
2653
+ * prior band).
2654
+ *
2655
+ * `opts.date` is the bake date for `{{date}}` (the engine is clockless — pass
2656
+ * e.g. `new Date().toISOString().slice(0, 10)`); omit to fall back to the
2657
+ * document's `/Info` date. `opts.images` supplies the pixels each
2658
+ * `HFItem` of `type: "image"` references by `imageId` — an iterable of
2659
+ * `[imageId, bytes]` (a `Map<number, Uint8Array>` works directly); an image
2660
+ * whose id is absent is skipped. Returns `true` on success.
2661
+ *
2662
+ * @example
2663
+ * doc.setRunningHeaderFooter(
2664
+ * {
2665
+ * default: {
2666
+ * header: [{ type: "image", imageId: 1, w: 80, h: 24, anchor: "left" }],
2667
+ * footer: [{ type: "text", text: "{{title}} — {{page}}/{{pages}}", anchor: "center" }],
2668
+ * },
2669
+ * firstPage: { header: [], footer: [] }, // blank cover
2670
+ * differentFirstPage: true,
2671
+ * differentOddEven: true,
2672
+ * evenPage: { header: [{ type: "text", text: "{{page}}", anchor: "left" }], footer: [] },
2673
+ * oddPage: { header: [{ type: "text", text: "{{page}}", anchor: "right" }], footer: [] },
2674
+ * },
2675
+ * { date: new Date().toISOString().slice(0, 10), images: new Map([[1, logoPng]]) }
2676
+ * );
2677
+ */
2678
+ setRunningHeaderFooter(def: RunningHeaderFooter, opts?: {
2679
+ date?: string;
2680
+ images?: Iterable<[number, Uint8Array]>;
2681
+ }): boolean;
2682
+ /**
2683
+ * The rich {@link RunningHeaderFooter} definition recorded by
2684
+ * {@link setRunningHeaderFooter} (read from the editor-meta sidecar — the
2685
+ * source of truth), or a minimal one reconstructed from a legacy flat
2686
+ * {@link setHeader}/{@link setFooter} bake, or `null` when neither is present.
2687
+ */
2688
+ runningHeaderFooter(): RunningHeaderFooter | null;
2524
2689
  renderPage(page: number, scale?: number): Uint8Array;
2525
2690
  /**
2526
2691
  * Rasterize a page to a PNG **without the page content stream's text** — glyphs
@@ -2545,6 +2710,18 @@ declare class GigaPdfDoc {
2545
2710
  * page; unknown indices are ignored.
2546
2711
  */
2547
2712
  renderPageExcluding(page: number, indices: number[], scale?: number): Uint8Array;
2713
+ /**
2714
+ * Rasterize a page to a PNG **excluding the ops inside a baked marked-content
2715
+ * span** named `marker` — and, when `skipText` is true, the page's text too — in
2716
+ * a **single** raster pass. For `marker = "GPHF"` (the default) this drops the
2717
+ * baked running header/footer band: the extraction views ({@link elements},
2718
+ * {@link textRuns}) already omit that band (it is never editable body content),
2719
+ * and this render omits it from the picture so it cannot double against an
2720
+ * editable overlay. With `skipText = true` it is the editor's text-free display
2721
+ * background minus the band; with `skipText = false`, the full page minus the
2722
+ * band. Like {@link renderPageNoText}, form-field widget appearances are omitted.
2723
+ */
2724
+ renderPageExcludingMarkedContent(page: number, scale?: number, skipText?: boolean, marker?: string): Uint8Array;
2548
2725
  /**
2549
2726
  * Embed an outline font program as a Type0 font and return its object number
2550
2727
  * (pass to {@link addText} / re-encoded by {@link replaceText}). Accepts
@@ -3176,4 +3353,4 @@ declare class GigaPdfDoc {
3176
3353
  regenerateFieldAppearance(name: string): boolean;
3177
3354
  }
3178
3355
 
3179
- export { type Action, type AfRelationship, type AnnotationInfo, type Attachment, type AttachmentOptions, type Bookmark, type Box, type CollectionConfig, type CollectionField, type CollectionFieldSubtype, type CollectionItem, type CollectionView, type Color, type DecodedImage, type Destination, type DocumentJavascript, type DocumentLanguage, type Element, type EmbeddedFont, type Exports, type FieldInfo, type FieldKind, type FieldStyle, type FileAttachmentIcon, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type GradientSpec, type GradientStop, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type InfoFields, type LayerInfo, type LinkInfo, type MergePart, type ModelOp, type NamedDest, type OutlineEntry, PAGE_BOX_KINDS, PAGE_TRANSITION_STYLES, type PageBoxKind, type PageBoxes, type PageInfo, type PageLabelRange, type PageLabelStyle, type PageLayout, type PageMargins, type PageMode, type PageTransition, type PageTransitionDimension, type PageTransitionDirection, type PageTransitionMotion, type PageTransitionStyle, type PathSegment, type PdfPermissions, type PdfVersion, type RadioOption, type SearchHit, type SignLtvOptions, type SignP12Options, type SignTsaOptions, type SignatureInfo, type SignatureReport, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type ViewerPreferences, type XlsxSheet, defaultCrlGet, defaultOcspPost, defaultTsaPost };
3356
+ export { type Action, type AfRelationship, type AnnotationInfo, type Attachment, type AttachmentOptions, type Bookmark, type Box, type CollectionConfig, type CollectionField, type CollectionFieldSubtype, type CollectionItem, type CollectionView, type Color, type DecodedImage, type Destination, type DocumentJavascript, type DocumentLanguage, type Element, type EmbeddedFont, type Exports, type FieldInfo, type FieldKind, type FieldStyle, type FileAttachmentIcon, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type GradientSpec, type GradientStop, type HFAlign, type HFItem, type HFZone, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type InfoFields, type LayerInfo, type LinkInfo, type MergePart, type ModelOp, type NamedDest, type OutlineEntry, PAGE_BOX_KINDS, PAGE_TRANSITION_STYLES, type PageBoxKind, type PageBoxes, type PageInfo, type PageLabelRange, type PageLabelStyle, type PageLayout, type PageMargins, type PageMode, type PageTransition, type PageTransitionDimension, type PageTransitionDirection, type PageTransitionMotion, type PageTransitionStyle, type PathSegment, type PdfPermissions, type PdfVersion, type RadioOption, type RunningHeaderFooter, type SearchHit, type SignLtvOptions, type SignP12Options, type SignTsaOptions, type SignatureInfo, type SignatureReport, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type ViewerPreferences, type XlsxSheet, defaultCrlGet, defaultOcspPost, defaultTsaPost };
package/dist/index.js CHANGED
@@ -125,6 +125,24 @@ var GigaPdfEngine = class _GigaPdfEngine {
125
125
  this.ex.gp_free(lenPtr, 4);
126
126
  return s ? JSON.parse(s) : [];
127
127
  }
128
+ /**
129
+ * Like {@link _str} but distinguishes a **null** result (the export returned a
130
+ * null pointer — e.g. an `Option::None`) from a present-but-empty string.
131
+ * Returns `null` only for the null pointer; otherwise the decoded string.
132
+ */
133
+ _strOrNull(call) {
134
+ const lenPtr = this.ex.gp_alloc(4);
135
+ const dataPtr = call(lenPtr);
136
+ if (dataPtr === 0) {
137
+ this.ex.gp_free(lenPtr, 4);
138
+ return null;
139
+ }
140
+ const len = this.dv().getUint32(lenPtr, true);
141
+ const s = dec.decode(this.u8().slice(dataPtr, dataPtr + len));
142
+ this.ex.gp_free(dataPtr, len);
143
+ this.ex.gp_free(lenPtr, 4);
144
+ return s;
145
+ }
128
146
  /**
129
147
  * Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
130
148
  * works identically in Node and the browser with no dependency (used to turn
@@ -1910,6 +1928,42 @@ var GigaPdfDoc = class {
1910
1928
  setPageMargins(page, m) {
1911
1929
  return this.ex().gp_set_page_margins(this.h, page, m.top, m.right, m.bottom, m.left) === 0;
1912
1930
  }
1931
+ /**
1932
+ * Store an **opaque** JSON string as the document's GigaPDF editor-metadata
1933
+ * sidecar — private editor state that travels with the PDF (catalog
1934
+ * `/GigaPDF /EditorMeta`, a FlateDecode-compressed stream). It is ignored by
1935
+ * every standard PDF reader and the round-trip survives save/open. Pass a JSON
1936
+ * **object** if you also use {@link setEditorMargins} (which read-modify-writes
1937
+ * that object's `margins` key). Returns `true` on success.
1938
+ */
1939
+ setEditorMeta(json) {
1940
+ return this.g._withStr(json, (p, l) => this.ex().gp_set_editor_meta(this.h, p, l)) === 0;
1941
+ }
1942
+ /**
1943
+ * The document's GigaPDF editor-metadata sidecar string (set by
1944
+ * {@link setEditorMeta}), or `null` when the document carries none.
1945
+ */
1946
+ editorMeta() {
1947
+ return this.g._strOrNull((o) => this.ex().gp_editor_meta(this.h, o));
1948
+ }
1949
+ /**
1950
+ * Record the editor's per-page **display** margins (points) in the
1951
+ * editor-metadata sidecar (under `margins`, keyed by page) **without touching
1952
+ * `/CropBox` or `/MediaBox`** — distinct from {@link setPageMargins}, which
1953
+ * performs a real visible recrop. Any other host keys in the sidecar are
1954
+ * preserved. Returns `true` on success.
1955
+ */
1956
+ setEditorMargins(page, m) {
1957
+ return this.ex().gp_set_editor_margins(this.h, page, m.top, m.right, m.bottom, m.left) === 0;
1958
+ }
1959
+ /**
1960
+ * The editor's per-page display margins (points) recorded for `page` by
1961
+ * {@link setEditorMargins}, or `null` when none were stored. Reads only the
1962
+ * sidecar — never `/CropBox`.
1963
+ */
1964
+ editorMargins(page) {
1965
+ return this.g._jsonOrNull((o) => this.ex().gp_editor_margins(this.h, page, o));
1966
+ }
1913
1967
  /**
1914
1968
  * All five page boundary boxes (`media`/`crop`/`bleed`/`trim`/`art`) for the
1915
1969
  * 1-based `page`, each as `[x0, y0, x1, y1]` in points, with ISO 32000-1
@@ -2056,6 +2110,78 @@ var GigaPdfDoc = class {
2056
2110
  (o) => this.ex().gp_header_footer(this.h, o)
2057
2111
  );
2058
2112
  }
2113
+ /**
2114
+ * Bake a **rich**, Word-like running header/footer from a {@link RunningHeaderFooter}
2115
+ * `def` (the source of truth — stored in the editor-meta sidecar, its visible
2116
+ * `/GPHF` band regenerated on every page). Text is set in an embedded font
2117
+ * (each item's `fontRef`, else the bundled OFL face — never base-14) and images
2118
+ * via the same path as {@link addImage}; both live inside the `/GPHF` span, so
2119
+ * they are excluded from {@link elements}/{@link textRuns} and masked by
2120
+ * {@link renderPageExcludingMarkedContent}. Idempotent (re-baking replaces the
2121
+ * prior band).
2122
+ *
2123
+ * `opts.date` is the bake date for `{{date}}` (the engine is clockless — pass
2124
+ * e.g. `new Date().toISOString().slice(0, 10)`); omit to fall back to the
2125
+ * document's `/Info` date. `opts.images` supplies the pixels each
2126
+ * `HFItem` of `type: "image"` references by `imageId` — an iterable of
2127
+ * `[imageId, bytes]` (a `Map<number, Uint8Array>` works directly); an image
2128
+ * whose id is absent is skipped. Returns `true` on success.
2129
+ *
2130
+ * @example
2131
+ * doc.setRunningHeaderFooter(
2132
+ * {
2133
+ * default: {
2134
+ * header: [{ type: "image", imageId: 1, w: 80, h: 24, anchor: "left" }],
2135
+ * footer: [{ type: "text", text: "{{title}} — {{page}}/{{pages}}", anchor: "center" }],
2136
+ * },
2137
+ * firstPage: { header: [], footer: [] }, // blank cover
2138
+ * differentFirstPage: true,
2139
+ * differentOddEven: true,
2140
+ * evenPage: { header: [{ type: "text", text: "{{page}}", anchor: "left" }], footer: [] },
2141
+ * oddPage: { header: [{ type: "text", text: "{{page}}", anchor: "right" }], footer: [] },
2142
+ * },
2143
+ * { date: new Date().toISOString().slice(0, 10), images: new Map([[1, logoPng]]) }
2144
+ * );
2145
+ */
2146
+ setRunningHeaderFooter(def, opts) {
2147
+ const entries = opts?.images ? Array.from(opts.images) : [];
2148
+ let total = 4;
2149
+ for (const [, bytes] of entries) total += 8 + bytes.length;
2150
+ const blob = new Uint8Array(total);
2151
+ const dv = new DataView(blob.buffer);
2152
+ let off = 0;
2153
+ dv.setUint32(off, entries.length >>> 0, true);
2154
+ off += 4;
2155
+ for (const [id, bytes] of entries) {
2156
+ dv.setUint32(off, id >>> 0, true);
2157
+ off += 4;
2158
+ dv.setUint32(off, bytes.length >>> 0, true);
2159
+ off += 4;
2160
+ blob.set(bytes, off);
2161
+ off += bytes.length;
2162
+ }
2163
+ return this.g._withStr(
2164
+ JSON.stringify(def),
2165
+ (dp, dl) => this.g._withOptStr(
2166
+ opts?.date,
2167
+ (tp, tl) => this.g._withBytes(
2168
+ blob,
2169
+ (ip, il) => this.ex().gp_set_running_header_footer(this.h, dp, dl, tp, tl, ip, il)
2170
+ )
2171
+ )
2172
+ ) === 0;
2173
+ }
2174
+ /**
2175
+ * The rich {@link RunningHeaderFooter} definition recorded by
2176
+ * {@link setRunningHeaderFooter} (read from the editor-meta sidecar — the
2177
+ * source of truth), or a minimal one reconstructed from a legacy flat
2178
+ * {@link setHeader}/{@link setFooter} bake, or `null` when neither is present.
2179
+ */
2180
+ runningHeaderFooter() {
2181
+ return this.g._jsonOrNull(
2182
+ (o) => this.ex().gp_running_header_footer(this.h, o)
2183
+ );
2184
+ }
2059
2185
  // render
2060
2186
  renderPage(page, scale = 1) {
2061
2187
  return this.g._buffer((o) => this.ex().gp_render_page(this.h, page, scale, o));
@@ -2092,6 +2218,33 @@ var GigaPdfDoc = class {
2092
2218
  )
2093
2219
  );
2094
2220
  }
2221
+ /**
2222
+ * Rasterize a page to a PNG **excluding the ops inside a baked marked-content
2223
+ * span** named `marker` — and, when `skipText` is true, the page's text too — in
2224
+ * a **single** raster pass. For `marker = "GPHF"` (the default) this drops the
2225
+ * baked running header/footer band: the extraction views ({@link elements},
2226
+ * {@link textRuns}) already omit that band (it is never editable body content),
2227
+ * and this render omits it from the picture so it cannot double against an
2228
+ * editable overlay. With `skipText = true` it is the editor's text-free display
2229
+ * background minus the band; with `skipText = false`, the full page minus the
2230
+ * band. Like {@link renderPageNoText}, form-field widget appearances are omitted.
2231
+ */
2232
+ renderPageExcludingMarkedContent(page, scale = 1, skipText = true, marker = "GPHF") {
2233
+ return this.g._buffer(
2234
+ (o) => this.g._withStr(
2235
+ marker,
2236
+ (p, l) => this.ex().gp_render_page_excluding_marked_content(
2237
+ this.h,
2238
+ page,
2239
+ scale,
2240
+ skipText ? 1 : 0,
2241
+ p,
2242
+ l,
2243
+ o
2244
+ )
2245
+ )
2246
+ );
2247
+ }
2095
2248
  // fonts — embed a downloaded font, then add real selectable text
2096
2249
  /**
2097
2250
  * Embed an outline font program as a Type0 font and return its object number