@qrcommunication/gigapdf-lib 0.66.0 → 0.67.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
@@ -18,6 +18,30 @@ type Exports = {
18
18
  gp_free(ptr: number, len: number): void;
19
19
  [k: string]: any;
20
20
  };
21
+ /**
22
+ * The eight PDF access permissions carried by an `/Encrypt` dictionary's `/P`
23
+ * entry (ISO 32000-1 §7.6.3.2, Table 22). Each flag is `true` when the action
24
+ * is **granted** to a user opening the document with the user password; the
25
+ * owner password always lifts every restriction.
26
+ */
27
+ type PdfPermissions = {
28
+ /** Print the document (low resolution unless {@link printHighRes} is also set). */
29
+ print: boolean;
30
+ /** Modify the document contents (other than annotating, filling or assembling). */
31
+ modify: boolean;
32
+ /** Copy or otherwise extract text and graphics. */
33
+ copy: boolean;
34
+ /** Add or modify annotations and fill in interactive form fields. */
35
+ annotate: boolean;
36
+ /** Fill in existing interactive form fields (even if {@link annotate} is clear). */
37
+ fillForms: boolean;
38
+ /** Extract text and graphics for accessibility tools. */
39
+ accessibility: boolean;
40
+ /** Assemble the document: insert, rotate and delete pages. */
41
+ assemble: boolean;
42
+ /** Print to a high-resolution device (requires {@link print}). */
43
+ printHighRes: boolean;
44
+ };
21
45
  /** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
22
46
  declare class GigaPdfEngine {
23
47
  private readonly ex;
@@ -84,6 +108,25 @@ declare class GigaPdfEngine {
84
108
  version: number;
85
109
  revision: number;
86
110
  };
111
+ /**
112
+ * Decode the eight access-permission flags from a `/P` permission bitmask
113
+ * (ISO 32000-1 Table 22) into named booleans (`true` = the action is
114
+ * granted). Reserved bits are ignored.
115
+ */
116
+ decodePermissions(p: number): PdfPermissions;
117
+ /**
118
+ * Read a PDF's access permissions **without decrypting it** (no password
119
+ * needed). Returns the eight named flags decoded from the `/Encrypt`
120
+ * dictionary's `/P`; an unencrypted document grants everything.
121
+ */
122
+ getPermissions(pdf: Uint8Array): PdfPermissions;
123
+ /**
124
+ * Pack eight access-permission flags into a signed 32-bit `/P` value
125
+ * (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
126
+ * object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
127
+ * via `opts.permissions`, or pass `opts.flags` directly.
128
+ */
129
+ permissionsToP(flags?: Partial<PdfPermissions>): number;
87
130
  /**
88
131
  * Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
89
132
  * place watermark/header text without embedding a font.
@@ -838,6 +881,31 @@ interface GigaStylePatch {
838
881
  strike?: boolean;
839
882
  color?: [number, number, number] | null;
840
883
  }
884
+ /**
885
+ * A paragraph-style patch for {@link ModelOp} `setParagraphStyle`: only the
886
+ * present fields are applied (mirror of `model::edit::ParaPatch`). Keys are the
887
+ * op's short names (`indent_left`, not `indent_left_pt`); values in PDF points.
888
+ * Omitting a field leaves the existing value unchanged.
889
+ */
890
+ interface GigaParaPatch {
891
+ align?: 'left' | 'center' | 'right' | 'justify';
892
+ indent_left?: number;
893
+ indent_right?: number;
894
+ /** First-line indent (positive) or hanging indent (negative), in points. */
895
+ first_line?: number;
896
+ space_before?: number;
897
+ space_after?: number;
898
+ /** Leading policy: font-natural, a size multiple, or a fixed point value. */
899
+ line_height?: {
900
+ t: 'normal';
901
+ } | {
902
+ t: 'multiple';
903
+ v: number;
904
+ } | {
905
+ t: 'points';
906
+ v: number;
907
+ };
908
+ }
841
909
  /** A typed spreadsheet cell value (tagged; mirror of `model::CellValue`). */
842
910
  type GigaCellValue = {
843
911
  t: 'empty';
@@ -909,6 +977,101 @@ type ModelOp = {
909
977
  row: number;
910
978
  col: number;
911
979
  value: GigaCellValue;
980
+ } | {
981
+ op: 'insertTableRow';
982
+ addr: GigaBlockAddr;
983
+ at: number;
984
+ } | {
985
+ op: 'deleteTableRow';
986
+ addr: GigaBlockAddr;
987
+ at: number;
988
+ } | {
989
+ op: 'insertTableColumn';
990
+ addr: GigaBlockAddr;
991
+ at: number;
992
+ } | {
993
+ op: 'deleteTableColumn';
994
+ addr: GigaBlockAddr;
995
+ at: number;
996
+ } | {
997
+ op: 'setCellSpan';
998
+ addr: GigaBlockAddr;
999
+ /** Row index in `rows`. */
1000
+ row: number;
1001
+ /** Cell index in `rows[row].cells` (not a grid column). */
1002
+ col: number;
1003
+ /** Columns the cell spans (clamped to ≥ 1). */
1004
+ col_span: number;
1005
+ /** Rows the cell spans (clamped to ≥ 1). */
1006
+ row_span: number;
1007
+ } | {
1008
+ op: 'insertSheetRow';
1009
+ addr: GigaBlockAddr;
1010
+ sheet: number;
1011
+ at: number;
1012
+ } | {
1013
+ op: 'deleteSheetRow';
1014
+ addr: GigaBlockAddr;
1015
+ sheet: number;
1016
+ at: number;
1017
+ } | {
1018
+ op: 'insertSheetColumn';
1019
+ addr: GigaBlockAddr;
1020
+ sheet: number;
1021
+ at: number;
1022
+ } | {
1023
+ op: 'deleteSheetColumn';
1024
+ addr: GigaBlockAddr;
1025
+ sheet: number;
1026
+ at: number;
1027
+ } | {
1028
+ op: 'setParagraphStyle';
1029
+ addr: GigaBlockAddr;
1030
+ patch: GigaParaPatch;
1031
+ } | {
1032
+ op: 'setListLevel';
1033
+ addr: GigaBlockAddr;
1034
+ level: number;
1035
+ } | {
1036
+ op: 'setListMarker';
1037
+ addr: GigaBlockAddr;
1038
+ marker: GigaListMarker;
1039
+ } | {
1040
+ op: 'setListOrdered';
1041
+ addr: GigaBlockAddr;
1042
+ ordered: boolean;
1043
+ } | {
1044
+ op: 'setBlockFrame';
1045
+ addr: GigaBlockAddr;
1046
+ rect: GigaRect;
1047
+ }
1048
+ /** `deg` is CCW; 0/90/180/270 snap to exact rotations, else an arbitrary angle. */
1049
+ | {
1050
+ op: 'setBlockRotation';
1051
+ addr: GigaBlockAddr;
1052
+ deg: number;
1053
+ }
1054
+ /** `color: null` clears the cell's shading; a triple sets it. */
1055
+ | {
1056
+ op: 'setCellShading';
1057
+ addr: GigaBlockAddr;
1058
+ row: number;
1059
+ col: number;
1060
+ color: [number, number, number] | null;
1061
+ } | {
1062
+ op: 'setRowHeight';
1063
+ addr: GigaBlockAddr;
1064
+ row: number;
1065
+ height: number;
1066
+ } | {
1067
+ op: 'setColWidth';
1068
+ addr: GigaBlockAddr;
1069
+ col: number;
1070
+ width: number;
1071
+ } | {
1072
+ op: 'setTableBorder';
1073
+ addr: GigaBlockAddr;
1074
+ border: GigaBorderStyle;
912
1075
  };
913
1076
  /**
914
1077
  * An image element from {@link GigaPdfDoc.imageElements}: its placement box
@@ -1586,6 +1749,15 @@ declare class GigaPdfDoc {
1586
1749
  saveEncrypted(password: string, fileId: string, opts?: {
1587
1750
  ownerPassword?: string;
1588
1751
  algorithm?: "rc4" | "aes128" | "aes256";
1752
+ /**
1753
+ * Named access permissions (ISO 32000-1 Table 22). Omitted flags default
1754
+ * to **granted**. Takes precedence over `permissions` when present.
1755
+ */
1756
+ flags?: Partial<PdfPermissions>;
1757
+ /**
1758
+ * Raw signed 32-bit `/P` bitmask. Use {@link flags} for a readable API.
1759
+ * Defaults to all permissions granted when neither is given.
1760
+ */
1589
1761
  permissions?: number;
1590
1762
  keySeed?: Uint8Array;
1591
1763
  }): Uint8Array;
@@ -1748,4 +1920,4 @@ declare class GigaPdfDoc {
1748
1920
  }): boolean;
1749
1921
  }
1750
1922
 
1751
- export { 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 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 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 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 OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
1923
+ export { 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 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 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 OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
package/dist/index.d.ts CHANGED
@@ -18,6 +18,30 @@ type Exports = {
18
18
  gp_free(ptr: number, len: number): void;
19
19
  [k: string]: any;
20
20
  };
21
+ /**
22
+ * The eight PDF access permissions carried by an `/Encrypt` dictionary's `/P`
23
+ * entry (ISO 32000-1 §7.6.3.2, Table 22). Each flag is `true` when the action
24
+ * is **granted** to a user opening the document with the user password; the
25
+ * owner password always lifts every restriction.
26
+ */
27
+ type PdfPermissions = {
28
+ /** Print the document (low resolution unless {@link printHighRes} is also set). */
29
+ print: boolean;
30
+ /** Modify the document contents (other than annotating, filling or assembling). */
31
+ modify: boolean;
32
+ /** Copy or otherwise extract text and graphics. */
33
+ copy: boolean;
34
+ /** Add or modify annotations and fill in interactive form fields. */
35
+ annotate: boolean;
36
+ /** Fill in existing interactive form fields (even if {@link annotate} is clear). */
37
+ fillForms: boolean;
38
+ /** Extract text and graphics for accessibility tools. */
39
+ accessibility: boolean;
40
+ /** Assemble the document: insert, rotate and delete pages. */
41
+ assemble: boolean;
42
+ /** Print to a high-resolution device (requires {@link print}). */
43
+ printHighRes: boolean;
44
+ };
21
45
  /** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
22
46
  declare class GigaPdfEngine {
23
47
  private readonly ex;
@@ -84,6 +108,25 @@ declare class GigaPdfEngine {
84
108
  version: number;
85
109
  revision: number;
86
110
  };
111
+ /**
112
+ * Decode the eight access-permission flags from a `/P` permission bitmask
113
+ * (ISO 32000-1 Table 22) into named booleans (`true` = the action is
114
+ * granted). Reserved bits are ignored.
115
+ */
116
+ decodePermissions(p: number): PdfPermissions;
117
+ /**
118
+ * Read a PDF's access permissions **without decrypting it** (no password
119
+ * needed). Returns the eight named flags decoded from the `/Encrypt`
120
+ * dictionary's `/P`; an unencrypted document grants everything.
121
+ */
122
+ getPermissions(pdf: Uint8Array): PdfPermissions;
123
+ /**
124
+ * Pack eight access-permission flags into a signed 32-bit `/P` value
125
+ * (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
126
+ * object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
127
+ * via `opts.permissions`, or pass `opts.flags` directly.
128
+ */
129
+ permissionsToP(flags?: Partial<PdfPermissions>): number;
87
130
  /**
88
131
  * Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
89
132
  * place watermark/header text without embedding a font.
@@ -838,6 +881,31 @@ interface GigaStylePatch {
838
881
  strike?: boolean;
839
882
  color?: [number, number, number] | null;
840
883
  }
884
+ /**
885
+ * A paragraph-style patch for {@link ModelOp} `setParagraphStyle`: only the
886
+ * present fields are applied (mirror of `model::edit::ParaPatch`). Keys are the
887
+ * op's short names (`indent_left`, not `indent_left_pt`); values in PDF points.
888
+ * Omitting a field leaves the existing value unchanged.
889
+ */
890
+ interface GigaParaPatch {
891
+ align?: 'left' | 'center' | 'right' | 'justify';
892
+ indent_left?: number;
893
+ indent_right?: number;
894
+ /** First-line indent (positive) or hanging indent (negative), in points. */
895
+ first_line?: number;
896
+ space_before?: number;
897
+ space_after?: number;
898
+ /** Leading policy: font-natural, a size multiple, or a fixed point value. */
899
+ line_height?: {
900
+ t: 'normal';
901
+ } | {
902
+ t: 'multiple';
903
+ v: number;
904
+ } | {
905
+ t: 'points';
906
+ v: number;
907
+ };
908
+ }
841
909
  /** A typed spreadsheet cell value (tagged; mirror of `model::CellValue`). */
842
910
  type GigaCellValue = {
843
911
  t: 'empty';
@@ -909,6 +977,101 @@ type ModelOp = {
909
977
  row: number;
910
978
  col: number;
911
979
  value: GigaCellValue;
980
+ } | {
981
+ op: 'insertTableRow';
982
+ addr: GigaBlockAddr;
983
+ at: number;
984
+ } | {
985
+ op: 'deleteTableRow';
986
+ addr: GigaBlockAddr;
987
+ at: number;
988
+ } | {
989
+ op: 'insertTableColumn';
990
+ addr: GigaBlockAddr;
991
+ at: number;
992
+ } | {
993
+ op: 'deleteTableColumn';
994
+ addr: GigaBlockAddr;
995
+ at: number;
996
+ } | {
997
+ op: 'setCellSpan';
998
+ addr: GigaBlockAddr;
999
+ /** Row index in `rows`. */
1000
+ row: number;
1001
+ /** Cell index in `rows[row].cells` (not a grid column). */
1002
+ col: number;
1003
+ /** Columns the cell spans (clamped to ≥ 1). */
1004
+ col_span: number;
1005
+ /** Rows the cell spans (clamped to ≥ 1). */
1006
+ row_span: number;
1007
+ } | {
1008
+ op: 'insertSheetRow';
1009
+ addr: GigaBlockAddr;
1010
+ sheet: number;
1011
+ at: number;
1012
+ } | {
1013
+ op: 'deleteSheetRow';
1014
+ addr: GigaBlockAddr;
1015
+ sheet: number;
1016
+ at: number;
1017
+ } | {
1018
+ op: 'insertSheetColumn';
1019
+ addr: GigaBlockAddr;
1020
+ sheet: number;
1021
+ at: number;
1022
+ } | {
1023
+ op: 'deleteSheetColumn';
1024
+ addr: GigaBlockAddr;
1025
+ sheet: number;
1026
+ at: number;
1027
+ } | {
1028
+ op: 'setParagraphStyle';
1029
+ addr: GigaBlockAddr;
1030
+ patch: GigaParaPatch;
1031
+ } | {
1032
+ op: 'setListLevel';
1033
+ addr: GigaBlockAddr;
1034
+ level: number;
1035
+ } | {
1036
+ op: 'setListMarker';
1037
+ addr: GigaBlockAddr;
1038
+ marker: GigaListMarker;
1039
+ } | {
1040
+ op: 'setListOrdered';
1041
+ addr: GigaBlockAddr;
1042
+ ordered: boolean;
1043
+ } | {
1044
+ op: 'setBlockFrame';
1045
+ addr: GigaBlockAddr;
1046
+ rect: GigaRect;
1047
+ }
1048
+ /** `deg` is CCW; 0/90/180/270 snap to exact rotations, else an arbitrary angle. */
1049
+ | {
1050
+ op: 'setBlockRotation';
1051
+ addr: GigaBlockAddr;
1052
+ deg: number;
1053
+ }
1054
+ /** `color: null` clears the cell's shading; a triple sets it. */
1055
+ | {
1056
+ op: 'setCellShading';
1057
+ addr: GigaBlockAddr;
1058
+ row: number;
1059
+ col: number;
1060
+ color: [number, number, number] | null;
1061
+ } | {
1062
+ op: 'setRowHeight';
1063
+ addr: GigaBlockAddr;
1064
+ row: number;
1065
+ height: number;
1066
+ } | {
1067
+ op: 'setColWidth';
1068
+ addr: GigaBlockAddr;
1069
+ col: number;
1070
+ width: number;
1071
+ } | {
1072
+ op: 'setTableBorder';
1073
+ addr: GigaBlockAddr;
1074
+ border: GigaBorderStyle;
912
1075
  };
913
1076
  /**
914
1077
  * An image element from {@link GigaPdfDoc.imageElements}: its placement box
@@ -1586,6 +1749,15 @@ declare class GigaPdfDoc {
1586
1749
  saveEncrypted(password: string, fileId: string, opts?: {
1587
1750
  ownerPassword?: string;
1588
1751
  algorithm?: "rc4" | "aes128" | "aes256";
1752
+ /**
1753
+ * Named access permissions (ISO 32000-1 Table 22). Omitted flags default
1754
+ * to **granted**. Takes precedence over `permissions` when present.
1755
+ */
1756
+ flags?: Partial<PdfPermissions>;
1757
+ /**
1758
+ * Raw signed 32-bit `/P` bitmask. Use {@link flags} for a readable API.
1759
+ * Defaults to all permissions granted when neither is given.
1760
+ */
1589
1761
  permissions?: number;
1590
1762
  keySeed?: Uint8Array;
1591
1763
  }): Uint8Array;
@@ -1748,4 +1920,4 @@ declare class GigaPdfDoc {
1748
1920
  }): boolean;
1749
1921
  }
1750
1922
 
1751
- export { 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 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 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 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 OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
1923
+ export { 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 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 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 OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
package/dist/index.js CHANGED
@@ -2,6 +2,16 @@
2
2
  import { loadDefaultWasmBytes } from "./node-fs.js";
3
3
  var enc = new TextEncoder();
4
4
  var dec = new TextDecoder();
5
+ var ALL_PERMISSIONS = {
6
+ print: true,
7
+ modify: true,
8
+ copy: true,
9
+ annotate: true,
10
+ fillForms: true,
11
+ accessibility: true,
12
+ assemble: true,
13
+ printHighRes: true
14
+ };
5
15
  var GigaPdfEngine = class _GigaPdfEngine {
6
16
  constructor(ex) {
7
17
  this.ex = ex;
@@ -218,6 +228,43 @@ var GigaPdfEngine = class _GigaPdfEngine {
218
228
  );
219
229
  return JSON.parse(dec.decode(json));
220
230
  }
231
+ /**
232
+ * Decode the eight access-permission flags from a `/P` permission bitmask
233
+ * (ISO 32000-1 Table 22) into named booleans (`true` = the action is
234
+ * granted). Reserved bits are ignored.
235
+ */
236
+ decodePermissions(p) {
237
+ const json = dec.decode(this._buffer((o) => this.ex.gp_permissions_from_p(p, o)));
238
+ return JSON.parse(json);
239
+ }
240
+ /**
241
+ * Read a PDF's access permissions **without decrypting it** (no password
242
+ * needed). Returns the eight named flags decoded from the `/Encrypt`
243
+ * dictionary's `/P`; an unencrypted document grants everything.
244
+ */
245
+ getPermissions(pdf) {
246
+ const { encrypted, permissions } = this.encryptionInfo(pdf);
247
+ return encrypted ? this.decodePermissions(permissions) : { ...ALL_PERMISSIONS };
248
+ }
249
+ /**
250
+ * Pack eight access-permission flags into a signed 32-bit `/P` value
251
+ * (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
252
+ * object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
253
+ * via `opts.permissions`, or pass `opts.flags` directly.
254
+ */
255
+ permissionsToP(flags = {}) {
256
+ const f = { ...ALL_PERMISSIONS, ...flags };
257
+ return this.ex.gp_permissions_to_p(
258
+ f.print ? 1 : 0,
259
+ f.modify ? 1 : 0,
260
+ f.copy ? 1 : 0,
261
+ f.annotate ? 1 : 0,
262
+ f.fillForms ? 1 : 0,
263
+ f.accessibility ? 1 : 0,
264
+ f.assemble ? 1 : 0,
265
+ f.printHighRes ? 1 : 0
266
+ );
267
+ }
221
268
  /**
222
269
  * Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
223
270
  * place watermark/header text without embedding a font.
@@ -1500,7 +1547,7 @@ var GigaPdfDoc = class {
1500
1547
  saveEncrypted(password, fileId, opts = {}) {
1501
1548
  const algo = opts.algorithm ?? "aes256";
1502
1549
  const algoCode = algo === "rc4" ? 0 : algo === "aes128" ? 1 : 2;
1503
- const permissions = opts.permissions ?? -44;
1550
+ const permissions = opts.flags !== void 0 ? this.g.permissionsToP(opts.flags) : opts.permissions ?? this.g.permissionsToP();
1504
1551
  let key = opts.keySeed ?? new Uint8Array(0);
1505
1552
  if (algoCode === 2 && key.length < 32) {
1506
1553
  const c = globalThis.crypto;