@qrcommunication/gigapdf-lib 0.50.0 → 0.52.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.ts CHANGED
@@ -271,6 +271,41 @@ declare class GigaPdfEngine {
271
271
  * inlined and never listed.
272
272
  */
273
273
  htmlNeededResources(html: string, header?: string, footer?: string): HtmlResourceNeed[];
274
+ /** Decode a model-JSON buffer returned by a `gp_model_*` export; `null` on an
275
+ * empty (error) result. */
276
+ private _modelOrNull;
277
+ /**
278
+ * Lower an Office document (DOCX/XLSX/PPTX/ODT/ODS/ODP, auto-detected) into the
279
+ * unified {@link GigaDocument} model. Returns `null` if the bytes aren't a
280
+ * recognized Office container.
281
+ */
282
+ officeToModel(office: Uint8Array): GigaDocument | null;
283
+ /** Lower an HTML string into the unified {@link GigaDocument} model. */
284
+ htmlToModel(html: string): GigaDocument;
285
+ /**
286
+ * Apply a batch of {@link ModelOp} edits to a model and return the edited
287
+ * model. Ops run in order; out-of-range addresses (and any op that can't be
288
+ * parsed) are silently skipped, so a partially-valid batch never throws.
289
+ */
290
+ applyModelOps(model: GigaDocument, ops: ModelOp[]): GigaDocument;
291
+ /** Raise a {@link GigaDocument} model to an editable Word document (`.docx`). */
292
+ modelToDocx(model: GigaDocument): Uint8Array;
293
+ /** Raise a model to an Excel workbook (`.xlsx`). */
294
+ modelToXlsx(model: GigaDocument): Uint8Array;
295
+ /** Raise a model to a PowerPoint presentation (`.pptx`). */
296
+ modelToPptx(model: GigaDocument): Uint8Array;
297
+ /** Raise a model to an OpenDocument Text (`.odt`). */
298
+ modelToOdt(model: GigaDocument): Uint8Array;
299
+ /** Raise a model to an OpenDocument Spreadsheet (`.ods`). */
300
+ modelToOds(model: GigaDocument): Uint8Array;
301
+ /** Raise a model to an OpenDocument Presentation (`.odp`). */
302
+ modelToOdp(model: GigaDocument): Uint8Array;
303
+ /** Raise a model back to a PDF. */
304
+ modelToPdf(model: GigaDocument): Uint8Array;
305
+ /** Raise a model to standalone HTML (decoded UTF-8 string). */
306
+ modelToHtml(model: GigaDocument): string;
307
+ /** Raise a model to RTF (decoded UTF-8 string). */
308
+ modelToRtf(model: GigaDocument): string;
274
309
  }
275
310
  /** A Google font the HTML engine needs (resolved from the catalogue). */
276
311
  interface HtmlFontRequest {
@@ -396,7 +431,206 @@ interface TextElementInfo {
396
431
  color: [number, number, number];
397
432
  /** Baseline rotation in degrees (0 = upright). */
398
433
  rotation: number;
434
+ /**
435
+ * Reading direction of this run by its strong characters: `"rtl"` for
436
+ * Arabic/Hebrew, `"ltr"` for Latin/Greek/Cyrillic/CJK, `"neutral"` when the
437
+ * run is only digits/punctuation/whitespace.
438
+ */
439
+ direction: 'ltr' | 'rtl' | 'neutral';
440
+ }
441
+ /**
442
+ * The aggregate language signal of a document from
443
+ * {@link GigaPdfDoc.documentLanguage}: its dominant reading {@link
444
+ * TextElementInfo.direction | direction}, writing system, and a best-effort
445
+ * ISO-639-1 language code (`"ar"`, `"he"`, `"zh"`/`"ja"`…), `undefined` when
446
+ * the script does not pin a single language (e.g. plain Latin).
447
+ */
448
+ interface DocumentLanguage {
449
+ direction: 'ltr' | 'rtl' | 'neutral';
450
+ /** Dominant script: `"arabic" | "hebrew" | "latin" | "greek" | "cyrillic" | "cjk" | "other"`. */
451
+ script: string;
452
+ /** Best-effort ISO-639-1 code, or `undefined` when undecidable. */
453
+ lang?: string;
454
+ }
455
+ /** A portable font fallback class (mirrors `convert::style::Generic`). */
456
+ type GigaGeneric = 'sans' | 'serif' | 'mono';
457
+ /** A run's character style (mirror of `model::style::CharStyle`'s JSON). */
458
+ interface GigaCharStyle {
459
+ family: string;
460
+ generic: GigaGeneric;
461
+ size_pt: number;
462
+ bold: boolean;
463
+ italic: boolean;
464
+ underline: boolean;
465
+ strike: boolean;
466
+ /** RGB `0..=1`, or `null` for default black. */
467
+ color: [number, number, number] | null;
468
+ valign: 'baseline' | 'super' | 'sub';
469
+ }
470
+ /** An inline node (tagged): a styled run, a line break, an image, or a link. */
471
+ type GigaInline = {
472
+ t: 'run';
473
+ text: string;
474
+ style: GigaCharStyle;
475
+ source_index: number | null;
476
+ } | {
477
+ t: 'break';
478
+ } | {
479
+ t: 'image';
480
+ [k: string]: unknown;
481
+ } | {
482
+ t: 'link';
483
+ [k: string]: unknown;
484
+ };
485
+ /** A block payload (tagged by `t`); only the common shapes are spelled out. */
486
+ interface GigaBlockKind {
487
+ t: 'paragraph' | 'heading' | 'list' | 'table' | 'image' | 'shape' | 'textbox' | 'sheet' | 'slide';
488
+ /** The variant body — e.g. a paragraph carries `{ runs: GigaInline[], … }`. */
489
+ v?: unknown;
490
+ }
491
+ /** A block: a stable id, an optional placement frame + rotation, and its kind. */
492
+ interface GigaBlock {
493
+ id: number;
494
+ frame: {
495
+ x: number;
496
+ y: number;
497
+ w: number;
498
+ h: number;
499
+ } | null;
500
+ rotation: {
501
+ t: 'd0' | 'd90' | 'd180' | 'd270' | 'deg';
502
+ v?: number;
503
+ };
504
+ kind: GigaBlockKind;
505
+ }
506
+ /** A page: a list of blocks; `absolute` flags slide/form (positioned) layout. */
507
+ interface GigaPage {
508
+ blocks: GigaBlock[];
509
+ absolute: boolean;
510
+ }
511
+ /** A section: one page geometry, optional running header/footer, and its pages. */
512
+ interface GigaSection {
513
+ geometry: {
514
+ width: number;
515
+ height: number;
516
+ [k: string]: unknown;
517
+ };
518
+ header: GigaBlock[] | null;
519
+ footer: GigaBlock[] | null;
520
+ pages: GigaPage[];
399
521
  }
522
+ /**
523
+ * The unified editable document model — the format-neutral tree every format
524
+ * lowers into and is reconstructed from. `v` is the envelope version. Leaves
525
+ * beyond what a host typically edits (`styles`, `outline`, `resources`) are
526
+ * carried opaquely so a round-trip preserves them.
527
+ */
528
+ interface GigaDocument {
529
+ v: number;
530
+ meta: {
531
+ title: string | null;
532
+ author: string | null;
533
+ subject: string | null;
534
+ keywords: string[];
535
+ lang: string | null;
536
+ };
537
+ styles: unknown;
538
+ sections: GigaSection[];
539
+ outline: unknown[];
540
+ resources: unknown;
541
+ }
542
+ /**
543
+ * A positional block address `[section, page, index]` (all zero-based) — the
544
+ * stable handle an edit op uses to target a block (mirrors `model::BlockAddr`).
545
+ */
546
+ type GigaBlockAddr = [section: number, page: number, index: number];
547
+ /**
548
+ * A character-style patch for restyle/insert ops: only the present fields are
549
+ * applied (mirror of `model::edit::StylePatch`). `color: null` clears the colour
550
+ * (→ default black); omitting `color` leaves it unchanged.
551
+ */
552
+ interface GigaStylePatch {
553
+ family?: string;
554
+ generic?: GigaGeneric;
555
+ size_pt?: number;
556
+ bold?: boolean;
557
+ italic?: boolean;
558
+ underline?: boolean;
559
+ strike?: boolean;
560
+ color?: [number, number, number] | null;
561
+ }
562
+ /** A typed spreadsheet cell value (tagged; mirror of `model::CellValue`). */
563
+ type GigaCellValue = {
564
+ t: 'empty';
565
+ } | {
566
+ t: 'text';
567
+ v: string;
568
+ } | {
569
+ t: 'number';
570
+ v: number;
571
+ } | {
572
+ t: 'bool';
573
+ v: boolean;
574
+ };
575
+ /**
576
+ * A single editing operation against a {@link GigaDocument} model, mirroring the
577
+ * JSON shape of `model::edit::ModelOp`. Pass an array to
578
+ * {@link GigaPdfEngine.applyModelOps}; ops run in order and out-of-range
579
+ * addresses are no-ops.
580
+ */
581
+ type ModelOp = {
582
+ op: 'setRunText';
583
+ addr: GigaBlockAddr;
584
+ run: number;
585
+ text: string;
586
+ } | {
587
+ op: 'restyleRun';
588
+ addr: GigaBlockAddr;
589
+ run: number;
590
+ style: GigaStylePatch;
591
+ } | {
592
+ op: 'insertRun';
593
+ addr: GigaBlockAddr;
594
+ run: number;
595
+ text: string;
596
+ style?: GigaStylePatch;
597
+ } | {
598
+ op: 'deleteRun';
599
+ addr: GigaBlockAddr;
600
+ run: number;
601
+ } | {
602
+ op: 'insertBlock';
603
+ addr: GigaBlockAddr;
604
+ block: GigaBlock;
605
+ } | {
606
+ op: 'deleteBlock';
607
+ addr: GigaBlockAddr;
608
+ } | {
609
+ op: 'moveBlock';
610
+ addr: GigaBlockAddr;
611
+ to: GigaBlockAddr;
612
+ } | {
613
+ op: 'setBlockText';
614
+ addr: GigaBlockAddr;
615
+ text: string;
616
+ } | {
617
+ op: 'restyleBlock';
618
+ addr: GigaBlockAddr;
619
+ style: GigaStylePatch;
620
+ } | {
621
+ op: 'setCellText';
622
+ addr: GigaBlockAddr;
623
+ row: number;
624
+ col: number;
625
+ text: string;
626
+ } | {
627
+ op: 'setSheetCell';
628
+ addr: GigaBlockAddr;
629
+ sheet: number;
630
+ row: number;
631
+ col: number;
632
+ value: GigaCellValue;
633
+ };
400
634
  /**
401
635
  * An image element from {@link GigaPdfDoc.imageElements}: its placement box
402
636
  * (page user space, origin bottom-left), the embeddable encoded bytes + format,
@@ -629,6 +863,37 @@ interface PageInfo {
629
863
  /** Raw `/MediaBox` `[x0, y0, x1, y1]` in user-space points (preserves origin). */
630
864
  mediaBox: [number, number, number, number];
631
865
  }
866
+ /** Per-side page margins, in points. */
867
+ interface PageMargins {
868
+ top: number;
869
+ right: number;
870
+ bottom: number;
871
+ left: number;
872
+ }
873
+ /** Horizontal alignment of header/footer text within the printable width. */
874
+ type HeaderFooterAlign = "left" | "center" | "right";
875
+ /**
876
+ * A running header/footer to bake onto an existing PDF (see {@link GigaPdfDoc.setHeader} /
877
+ * {@link GigaPdfDoc.setFooter}). `text` may contain the tokens `{{page}}` (1-based page
878
+ * number) and `{{pages}}` (total page count), substituted per page. Text is drawn in
879
+ * standard Helvetica inside the top (header) / bottom (footer) margin band.
880
+ */
881
+ interface HeaderFooterSpec {
882
+ /** Template text, with `{{page}}` / `{{pages}}` tokens. */
883
+ text: string;
884
+ /** Horizontal alignment (default `"left"`). */
885
+ align?: HeaderFooterAlign;
886
+ /** Font size in points (default `10`). */
887
+ fontSize?: number;
888
+ /** RGB fill colour, `0..1` per channel (default black `[0,0,0]`). */
889
+ color?: [number, number, number];
890
+ /** Inclusive 1-based page range `[first, last]`; omit for every page. */
891
+ pageRange?: [number, number] | null;
892
+ /** Draw on the first page of the range too (default `true`). */
893
+ showOnFirstPage?: boolean;
894
+ /** Band height from the page edge, in points (default `36`). */
895
+ bandHeight?: number;
896
+ }
632
897
  /** Visual styling for a newly-created form field. */
633
898
  interface FieldStyle {
634
899
  /** Text size in points; `0` (default) auto-sizes to the field box. */
@@ -670,6 +935,15 @@ declare class GigaPdfDoc {
670
935
  * for a reader's per-run text layer (which `elements()` omits font + colour).
671
936
  */
672
937
  textElements(page: number): TextElementInfo[];
938
+ /**
939
+ * The document's aggregate language signal — its dominant reading direction
940
+ * (`ltr`/`rtl`/`neutral`), writing system, and a best-effort ISO-639-1
941
+ * language code — computed across every page's decoded text. Lets a host
942
+ * pick fonts, set the UI direction or label the document without its own bidi
943
+ * pass (e.g. detect an Arabic/Hebrew/Japanese PDF). `lang` is omitted when the
944
+ * script does not pin a single language.
945
+ */
946
+ documentLanguage(): DocumentLanguage;
673
947
  /**
674
948
  * Every image element on a page: its placement box (user space, bottom-left),
675
949
  * the embeddable encoded bytes (`data`) + `format` (`jpeg`/`png`/`jp2`/
@@ -768,6 +1042,27 @@ declare class GigaPdfDoc {
768
1042
  copyPage(page: number): number;
769
1043
  /** A page's size (points) and `/Rotate` (0/90/180/270). */
770
1044
  pageInfo(page: number): PageInfo;
1045
+ /**
1046
+ * A page's margins (points): the gap between `/CropBox` and `/MediaBox` when a
1047
+ * CropBox exists, else estimated from the content bounding box.
1048
+ */
1049
+ pageMargins(page: number): PageMargins;
1050
+ /**
1051
+ * Set a page's margins (points) by insetting its `/CropBox` from the `/MediaBox`
1052
+ * — a real, visible margin change. Returns `true` on success.
1053
+ */
1054
+ setPageMargins(page: number, m: PageMargins): boolean;
1055
+ /**
1056
+ * Bake a running header onto every in-range page (idempotent: re-baking
1057
+ * replaces the prior header). Returns `true` on success.
1058
+ */
1059
+ setHeader(spec: HeaderFooterSpec): boolean;
1060
+ /** Bake a running footer onto every in-range page (idempotent). */
1061
+ setFooter(spec: HeaderFooterSpec): boolean;
1062
+ /** Remove every previously-baked running header from all pages. */
1063
+ removeHeaders(): boolean;
1064
+ /** Remove every previously-baked running footer from all pages. */
1065
+ removeFooters(): boolean;
771
1066
  renderPage(page: number, scale?: number): Uint8Array;
772
1067
  /**
773
1068
  * Embed an outline font program as a Type0 font and return its object number
@@ -823,6 +1118,15 @@ declare class GigaPdfDoc {
823
1118
  embeddedFonts(): EmbeddedFont[];
824
1119
  toText(): string;
825
1120
  toHtml(): string;
1121
+ /**
1122
+ * Reconstruct this PDF into the **unified editable model** — the
1123
+ * format-neutral {@link GigaDocument} tree (sections → pages → blocks → runs)
1124
+ * that every format lowers into. Edit it with
1125
+ * {@link GigaPdfEngine.applyModelOps}, then export it to any target with
1126
+ * {@link GigaPdfEngine.modelToDocx} / {@link GigaPdfEngine.modelToPdf} / … —
1127
+ * the foundation for editing any document indifferently of its source format.
1128
+ */
1129
+ toModel(): GigaDocument;
826
1130
  toDocx(): Uint8Array;
827
1131
  toPptx(): Uint8Array;
828
1132
  /** Convert to an editable OpenDocument Presentation (`.odp`). */
@@ -998,4 +1302,4 @@ declare class GigaPdfDoc {
998
1302
  }): boolean;
999
1303
  }
1000
1304
 
1001
- export { ALL_OCR_SCRIPTS, type AnnotationInfo, type Attachment, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type NamedDest, type OcrScript, type OcrWord, type OutlineEntry, type PageInfo, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
1305
+ export { ALL_OCR_SCRIPTS, type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaInline, type GigaPage, GigaPdfDoc, GigaPdfEngine, type GigaSection, type GigaStylePatch, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OcrScript, type OcrWord, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
package/dist/index.js CHANGED
@@ -639,6 +639,113 @@ var GigaPdfEngine = class _GigaPdfEngine {
639
639
  )
640
640
  );
641
641
  }
642
+ // ── unified editable model: lower / edit / raise ───────────────────────────
643
+ //
644
+ // The {@link GigaDocument} model is a format-neutral tree (sections → pages →
645
+ // blocks → runs). Lower any format into it (`*ToModel`), edit it with
646
+ // {@link applyModelOps}, then raise it back to any format (`modelTo*`). This is
647
+ // the substrate for a universal editor that edits every format the same way.
648
+ /** Decode a model-JSON buffer returned by a `gp_model_*` export; `null` on an
649
+ * empty (error) result. */
650
+ _modelOrNull(call) {
651
+ const s = this._str(call);
652
+ return s ? JSON.parse(s) : null;
653
+ }
654
+ /**
655
+ * Lower an Office document (DOCX/XLSX/PPTX/ODT/ODS/ODP, auto-detected) into the
656
+ * unified {@link GigaDocument} model. Returns `null` if the bytes aren't a
657
+ * recognized Office container.
658
+ */
659
+ officeToModel(office) {
660
+ return this._withBytes(
661
+ office,
662
+ (p, l) => this._modelOrNull((o) => this.ex.gp_model_from_office(p, l, o))
663
+ );
664
+ }
665
+ /** Lower an HTML string into the unified {@link GigaDocument} model. */
666
+ htmlToModel(html) {
667
+ return this._withStr(
668
+ html,
669
+ (p, l) => JSON.parse(this._str((o) => this.ex.gp_model_from_html(p, l, o)))
670
+ );
671
+ }
672
+ /**
673
+ * Apply a batch of {@link ModelOp} edits to a model and return the edited
674
+ * model. Ops run in order; out-of-range addresses (and any op that can't be
675
+ * parsed) are silently skipped, so a partially-valid batch never throws.
676
+ */
677
+ applyModelOps(model, ops) {
678
+ return this._withStr(
679
+ JSON.stringify(model),
680
+ (mp, ml) => this._withStr(
681
+ JSON.stringify(ops),
682
+ (op, ol) => JSON.parse(this._str((o) => this.ex.gp_model_apply_ops(mp, ml, op, ol, o)))
683
+ )
684
+ );
685
+ }
686
+ /** Raise a {@link GigaDocument} model to an editable Word document (`.docx`). */
687
+ modelToDocx(model) {
688
+ return this._withStr(
689
+ JSON.stringify(model),
690
+ (p, l) => this._buffer((o) => this.ex.gp_model_to_docx(p, l, o))
691
+ );
692
+ }
693
+ /** Raise a model to an Excel workbook (`.xlsx`). */
694
+ modelToXlsx(model) {
695
+ return this._withStr(
696
+ JSON.stringify(model),
697
+ (p, l) => this._buffer((o) => this.ex.gp_model_to_xlsx(p, l, o))
698
+ );
699
+ }
700
+ /** Raise a model to a PowerPoint presentation (`.pptx`). */
701
+ modelToPptx(model) {
702
+ return this._withStr(
703
+ JSON.stringify(model),
704
+ (p, l) => this._buffer((o) => this.ex.gp_model_to_pptx(p, l, o))
705
+ );
706
+ }
707
+ /** Raise a model to an OpenDocument Text (`.odt`). */
708
+ modelToOdt(model) {
709
+ return this._withStr(
710
+ JSON.stringify(model),
711
+ (p, l) => this._buffer((o) => this.ex.gp_model_to_odt(p, l, o))
712
+ );
713
+ }
714
+ /** Raise a model to an OpenDocument Spreadsheet (`.ods`). */
715
+ modelToOds(model) {
716
+ return this._withStr(
717
+ JSON.stringify(model),
718
+ (p, l) => this._buffer((o) => this.ex.gp_model_to_ods(p, l, o))
719
+ );
720
+ }
721
+ /** Raise a model to an OpenDocument Presentation (`.odp`). */
722
+ modelToOdp(model) {
723
+ return this._withStr(
724
+ JSON.stringify(model),
725
+ (p, l) => this._buffer((o) => this.ex.gp_model_to_odp(p, l, o))
726
+ );
727
+ }
728
+ /** Raise a model back to a PDF. */
729
+ modelToPdf(model) {
730
+ return this._withStr(
731
+ JSON.stringify(model),
732
+ (p, l) => this._buffer((o) => this.ex.gp_model_to_pdf(p, l, o))
733
+ );
734
+ }
735
+ /** Raise a model to standalone HTML (decoded UTF-8 string). */
736
+ modelToHtml(model) {
737
+ return this._withStr(
738
+ JSON.stringify(model),
739
+ (p, l) => this._str((o) => this.ex.gp_model_to_html(p, l, o))
740
+ );
741
+ }
742
+ /** Raise a model to RTF (decoded UTF-8 string). */
743
+ modelToRtf(model) {
744
+ return this._withStr(
745
+ JSON.stringify(model),
746
+ (p, l) => this._str((o) => this.ex.gp_model_to_rtf(p, l, o))
747
+ );
748
+ }
642
749
  };
643
750
  function packHtmlResources(resources) {
644
751
  let size = 4;
@@ -742,6 +849,24 @@ var GigaPdfDoc = class {
742
849
  textElements(page) {
743
850
  return this.g._json((o) => this.ex().gp_text_elements_json(this.h, page, o));
744
851
  }
852
+ /**
853
+ * The document's aggregate language signal — its dominant reading direction
854
+ * (`ltr`/`rtl`/`neutral`), writing system, and a best-effort ISO-639-1
855
+ * language code — computed across every page's decoded text. Lets a host
856
+ * pick fonts, set the UI direction or label the document without its own bidi
857
+ * pass (e.g. detect an Arabic/Hebrew/Japanese PDF). `lang` is omitted when the
858
+ * script does not pin a single language.
859
+ */
860
+ documentLanguage() {
861
+ const raw = this.g._json(
862
+ (o) => this.ex().gp_document_language(this.h, o)
863
+ );
864
+ return {
865
+ direction: raw.direction,
866
+ script: raw.script,
867
+ ...raw.lang != null ? { lang: raw.lang } : {}
868
+ };
869
+ }
745
870
  /**
746
871
  * Every image element on a page: its placement box (user space, bottom-left),
747
872
  * the embeddable encoded bytes (`data`) + `format` (`jpeg`/`png`/`jp2`/
@@ -990,6 +1115,40 @@ var GigaPdfDoc = class {
990
1115
  pageInfo(page) {
991
1116
  return this.g._json((o) => this.ex().gp_page_info_json(this.h, page, o));
992
1117
  }
1118
+ // margins + running header/footer
1119
+ /**
1120
+ * A page's margins (points): the gap between `/CropBox` and `/MediaBox` when a
1121
+ * CropBox exists, else estimated from the content bounding box.
1122
+ */
1123
+ pageMargins(page) {
1124
+ return this.g._json((o) => this.ex().gp_page_margins(this.h, page, o));
1125
+ }
1126
+ /**
1127
+ * Set a page's margins (points) by insetting its `/CropBox` from the `/MediaBox`
1128
+ * — a real, visible margin change. Returns `true` on success.
1129
+ */
1130
+ setPageMargins(page, m) {
1131
+ return this.ex().gp_set_page_margins(this.h, page, m.top, m.right, m.bottom, m.left) === 0;
1132
+ }
1133
+ /**
1134
+ * Bake a running header onto every in-range page (idempotent: re-baking
1135
+ * replaces the prior header). Returns `true` on success.
1136
+ */
1137
+ setHeader(spec) {
1138
+ return this.g._withStr(JSON.stringify(spec), (p, l) => this.ex().gp_set_header(this.h, p, l)) === 0;
1139
+ }
1140
+ /** Bake a running footer onto every in-range page (idempotent). */
1141
+ setFooter(spec) {
1142
+ return this.g._withStr(JSON.stringify(spec), (p, l) => this.ex().gp_set_footer(this.h, p, l)) === 0;
1143
+ }
1144
+ /** Remove every previously-baked running header from all pages. */
1145
+ removeHeaders() {
1146
+ return this.ex().gp_remove_headers(this.h) === 0;
1147
+ }
1148
+ /** Remove every previously-baked running footer from all pages. */
1149
+ removeFooters() {
1150
+ return this.ex().gp_remove_footers(this.h) === 0;
1151
+ }
993
1152
  // render
994
1153
  renderPage(page, scale = 1) {
995
1154
  return this.g._buffer((o) => this.ex().gp_render_page(this.h, page, scale, o));
@@ -1115,6 +1274,17 @@ var GigaPdfDoc = class {
1115
1274
  toHtml() {
1116
1275
  return this.g._str((o) => this.ex().gp_to_html(this.h, o));
1117
1276
  }
1277
+ /**
1278
+ * Reconstruct this PDF into the **unified editable model** — the
1279
+ * format-neutral {@link GigaDocument} tree (sections → pages → blocks → runs)
1280
+ * that every format lowers into. Edit it with
1281
+ * {@link GigaPdfEngine.applyModelOps}, then export it to any target with
1282
+ * {@link GigaPdfEngine.modelToDocx} / {@link GigaPdfEngine.modelToPdf} / … —
1283
+ * the foundation for editing any document indifferently of its source format.
1284
+ */
1285
+ toModel() {
1286
+ return JSON.parse(this.g._str((o) => this.ex().gp_model_from_pdf(this.h, o)));
1287
+ }
1118
1288
  toDocx() {
1119
1289
  return this.g._buffer((o) => this.ex().gp_to_docx(this.h, o));
1120
1290
  }