@embedpdf/models 2.1.2 → 2.3.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/pdf.d.ts CHANGED
@@ -48,6 +48,19 @@ export interface PdfDocumentObject {
48
48
  * Pages in this document
49
49
  */
50
50
  pages: PdfPageObject[];
51
+ /**
52
+ * Whether the document is encrypted
53
+ */
54
+ isEncrypted: boolean;
55
+ /**
56
+ * Whether owner permissions are currently unlocked
57
+ */
58
+ isOwnerUnlocked: boolean;
59
+ /**
60
+ * Raw permission flags from FPDF_GetDocPermissions.
61
+ * Use PdfPermissionFlag to check individual permissions.
62
+ */
63
+ permissions: number;
51
64
  }
52
65
  /**
53
66
  * metadata of pdf document
@@ -816,6 +829,35 @@ export declare enum PdfAnnotationLineEnding {
816
829
  */
817
830
  Unknown = 10
818
831
  }
832
+ /**
833
+ * Reply type of annotation (RT property per ISO 32000-2)
834
+ *
835
+ * Specifies how an annotation relates to another annotation when it is
836
+ * a reply (via IRT - In Reply To). Valid values are:
837
+ * - Reply (/R): Normal comment reply (default if RT is missing)
838
+ * - Group (/Group): Logical grouping of annotations
839
+ *
840
+ * @public
841
+ */
842
+ export declare enum PdfAnnotationReplyType {
843
+ /**
844
+ * Unknown or invalid reply type
845
+ */
846
+ Unknown = 0,
847
+ /**
848
+ * /R - Comment reply (default if RT is missing)
849
+ * The annotation is a child comment of the annotation referenced by IRT.
850
+ * Used for comment threads, reviewer discussions, sticky-note replies.
851
+ */
852
+ Reply = 1,
853
+ /**
854
+ * /Group - Logical grouping
855
+ * The annotation is grouped with the annotation referenced by IRT.
856
+ * They represent the same logical object. Used when multiple annotations
857
+ * act as one unit (e.g., visual shape + metadata/label).
858
+ */
859
+ Group = 2
860
+ }
819
861
  /**
820
862
  * Basic information of pdf annotation
821
863
  *
@@ -870,6 +912,14 @@ export interface PdfAnnotationObjectBase {
870
912
  * Custom data of the annotation
871
913
  */
872
914
  custom?: any;
915
+ /**
916
+ * In reply to annotation id (IRT - for grouping or reply threads)
917
+ */
918
+ inReplyToId?: string;
919
+ /**
920
+ * Reply type (how this annotation relates to the parent via IRT)
921
+ */
922
+ replyType?: PdfAnnotationReplyType;
873
923
  }
874
924
  /**
875
925
  * Popup annotation
@@ -887,10 +937,6 @@ export interface PdfPopupAnnoObject extends PdfAnnotationObjectBase {
887
937
  * Whether the popup is opened or not
888
938
  */
889
939
  open: boolean;
890
- /**
891
- * In reply to id
892
- */
893
- inReplyToId?: string;
894
940
  }
895
941
  /**
896
942
  * Pdf Link annotation
@@ -904,6 +950,22 @@ export interface PdfLinkAnnoObject extends PdfAnnotationObjectBase {
904
950
  * target of the link
905
951
  */
906
952
  target: PdfLinkTarget | undefined;
953
+ /**
954
+ * Stroke color of the link border (e.g., "#00A5E4")
955
+ */
956
+ strokeColor?: string;
957
+ /**
958
+ * Width of the link border (default: 2)
959
+ */
960
+ strokeWidth?: number;
961
+ /**
962
+ * Style of the link border (default: UNDERLINE)
963
+ */
964
+ strokeStyle?: PdfAnnotationBorderStyle;
965
+ /**
966
+ * Dash pattern for dashed border style
967
+ */
968
+ strokeDashArray?: number[];
907
969
  }
908
970
  /**
909
971
  * Pdf Text annotation
@@ -925,10 +987,6 @@ export interface PdfTextAnnoObject extends PdfAnnotationObjectBase {
925
987
  * opacity of text annotation
926
988
  */
927
989
  opacity?: number;
928
- /**
929
- * In reply to id
930
- */
931
- inReplyToId?: string;
932
990
  /**
933
991
  * State of the text annotation
934
992
  */
@@ -1195,9 +1253,13 @@ export interface PdfInkAnnoObject extends PdfAnnotationObjectBase {
1195
1253
  */
1196
1254
  inkList: PdfInkListObject[];
1197
1255
  /**
1198
- * color of ink annotation
1256
+ * Color of the ink stroke (preferred over deprecated `color`)
1199
1257
  */
1200
- color: string;
1258
+ strokeColor?: string;
1259
+ /**
1260
+ * @deprecated Use strokeColor instead. Will be removed in next major version.
1261
+ */
1262
+ color?: string;
1201
1263
  /**
1202
1264
  * opacity of ink annotation
1203
1265
  */
@@ -1351,9 +1413,13 @@ export interface PdfHighlightAnnoObject extends PdfAnnotationObjectBase {
1351
1413
  */
1352
1414
  contents?: string;
1353
1415
  /**
1354
- * color of highlight annotation
1416
+ * Color of the highlight markup (preferred over deprecated `color`)
1355
1417
  */
1356
- color: string;
1418
+ strokeColor?: string;
1419
+ /**
1420
+ * @deprecated Use strokeColor instead. Will be removed in next major version.
1421
+ */
1422
+ color?: string;
1357
1423
  /**
1358
1424
  * opacity of highlight annotation
1359
1425
  */
@@ -1595,19 +1661,23 @@ export interface PdfSquigglyAnnoObject extends PdfAnnotationObjectBase {
1595
1661
  /** {@inheritDoc PdfAnnotationObjectBase.type} */
1596
1662
  type: PdfAnnotationSubtype.SQUIGGLY;
1597
1663
  /**
1598
- * Text contents of the highlight annotation
1664
+ * Text contents of the squiggly annotation
1599
1665
  */
1600
1666
  contents?: string;
1601
1667
  /**
1602
- * color of strike out annotation
1668
+ * Color of the squiggly markup (preferred over deprecated `color`)
1603
1669
  */
1604
- color: string;
1670
+ strokeColor?: string;
1605
1671
  /**
1606
- * opacity of strike out annotation
1672
+ * @deprecated Use strokeColor instead. Will be removed in next major version.
1673
+ */
1674
+ color?: string;
1675
+ /**
1676
+ * opacity of squiggly annotation
1607
1677
  */
1608
1678
  opacity: number;
1609
1679
  /**
1610
- * quads of highlight area
1680
+ * quads of squiggly area
1611
1681
  */
1612
1682
  segmentRects: Rect[];
1613
1683
  }
@@ -1620,19 +1690,23 @@ export interface PdfUnderlineAnnoObject extends PdfAnnotationObjectBase {
1620
1690
  /** {@inheritDoc PdfAnnotationObjectBase.type} */
1621
1691
  type: PdfAnnotationSubtype.UNDERLINE;
1622
1692
  /**
1623
- * Text contents of the highlight annotation
1693
+ * Text contents of the underline annotation
1624
1694
  */
1625
1695
  contents?: string;
1626
1696
  /**
1627
- * color of strike out annotation
1697
+ * Color of the underline markup (preferred over deprecated `color`)
1628
1698
  */
1629
- color: string;
1699
+ strokeColor?: string;
1630
1700
  /**
1631
- * opacity of strike out annotation
1701
+ * @deprecated Use strokeColor instead. Will be removed in next major version.
1702
+ */
1703
+ color?: string;
1704
+ /**
1705
+ * opacity of underline annotation
1632
1706
  */
1633
1707
  opacity: number;
1634
1708
  /**
1635
- * quads of highlight area
1709
+ * quads of underline area
1636
1710
  */
1637
1711
  segmentRects: Rect[];
1638
1712
  }
@@ -1649,15 +1723,19 @@ export interface PdfStrikeOutAnnoObject extends PdfAnnotationObjectBase {
1649
1723
  */
1650
1724
  contents?: string;
1651
1725
  /**
1652
- * color of strike out annotation
1726
+ * Color of the strikeout markup (preferred over deprecated `color`)
1653
1727
  */
1654
- color: string;
1728
+ strokeColor?: string;
1729
+ /**
1730
+ * @deprecated Use strokeColor instead. Will be removed in next major version.
1731
+ */
1732
+ color?: string;
1655
1733
  /**
1656
1734
  * opacity of strike out annotation
1657
1735
  */
1658
1736
  opacity: number;
1659
1737
  /**
1660
- * quads of highlight area
1738
+ * quads of strikeout area
1661
1739
  */
1662
1740
  segmentRects: Rect[];
1663
1741
  }
@@ -1707,7 +1785,11 @@ export interface PdfFreeTextAnnoObject extends PdfAnnotationObjectBase {
1707
1785
  */
1708
1786
  opacity: number;
1709
1787
  /**
1710
- * Background color of the free text annotation
1788
+ * Background/fill color of the free text annotation (matches shape convention)
1789
+ */
1790
+ color?: string;
1791
+ /**
1792
+ * @deprecated Use color instead. Will be removed in next major version.
1711
1793
  */
1712
1794
  backgroundColor?: string;
1713
1795
  /**
@@ -2054,15 +2136,53 @@ export interface PdfAnnotationTransformation {
2054
2136
  * @public
2055
2137
  */
2056
2138
  export type PdfFileContent = ArrayBuffer;
2057
- export declare enum PdfPermission {
2058
- PrintDocument = 8,
2059
- ModifyContent = 16,
2060
- CopyOrExtract = 32,
2061
- AddOrModifyTextAnnot = 64,
2062
- FillInExistingForm = 512,
2063
- ExtractTextOrGraphics = 1024,
2064
- AssembleDocument = 2048,
2065
- PrintHighQuality = 4096
2139
+ /**
2140
+ * PDF permission flags per ISO 32000-1 Table 22
2141
+ * These are the flags to pass to setDocumentEncryption indicating what actions ARE ALLOWED.
2142
+ * Use buildPermissions() helper to combine flags.
2143
+ *
2144
+ * @public
2145
+ */
2146
+ export declare enum PdfPermissionFlag {
2147
+ /** Bit 3: Print (possibly degraded quality) */
2148
+ Print = 4,
2149
+ /** Bit 4: Modify document contents */
2150
+ ModifyContents = 8,
2151
+ /** Bit 5: Copy/extract text and graphics */
2152
+ CopyContents = 16,
2153
+ /** Bit 6: Add/modify annotations, fill forms */
2154
+ ModifyAnnotations = 32,
2155
+ /** Bit 9: Fill in existing form fields */
2156
+ FillForms = 256,
2157
+ /** Bit 10: Extract for accessibility */
2158
+ ExtractForAccessibility = 512,
2159
+ /** Bit 11: Assemble document (insert, rotate, delete pages) */
2160
+ AssembleDocument = 1024,
2161
+ /** Bit 12: High quality print */
2162
+ PrintHighQuality = 2048,
2163
+ /** Common combination: Allow all permissions */
2164
+ AllowAll = 3900
2165
+ }
2166
+ /**
2167
+ * Helper function to combine permission flags for setDocumentEncryption.
2168
+ * Note: PrintHighQuality automatically includes Print (enforced in C++ layer as well).
2169
+ *
2170
+ * @param flags - Permission flags to combine
2171
+ * @returns Combined permission flags as a number
2172
+ *
2173
+ * @public
2174
+ */
2175
+ export declare function buildPermissions(...flags: PdfPermissionFlag[]): number;
2176
+ /**
2177
+ * Error thrown when a permission check fails.
2178
+ *
2179
+ * @public
2180
+ */
2181
+ export declare class PermissionDeniedError extends Error {
2182
+ readonly requiredFlags: PdfPermissionFlag[];
2183
+ readonly currentPermissions: number;
2184
+ readonly name = "PermissionDeniedError";
2185
+ constructor(requiredFlags: PdfPermissionFlag[], currentPermissions: number);
2066
2186
  }
2067
2187
  export declare enum PdfPageFlattenFlag {
2068
2188
  Display = 0,
@@ -2634,6 +2754,43 @@ export interface PdfEngine<T = Blob> {
2634
2754
  * @returns task that all documents are closed or not
2635
2755
  */
2636
2756
  closeAllDocuments: () => PdfTask<boolean>;
2757
+ /**
2758
+ * Sets AES-256 encryption on a document.
2759
+ * Must be called before saveAsCopy() for encryption to take effect.
2760
+ * @param doc - pdf document
2761
+ * @param userPassword - Password to open document (empty = no open password)
2762
+ * @param ownerPassword - Password to change permissions (required)
2763
+ * @param allowedFlags - OR'd PdfPermissionFlag values indicating allowed actions
2764
+ * @returns task indicating success or failure
2765
+ */
2766
+ setDocumentEncryption: (doc: PdfDocumentObject, userPassword: string, ownerPassword: string, allowedFlags: number) => PdfTask<boolean>;
2767
+ /**
2768
+ * Marks document for encryption removal on save.
2769
+ * Call this to remove password protection when saving.
2770
+ * @param doc - pdf document
2771
+ * @returns task indicating success
2772
+ */
2773
+ removeEncryption: (doc: PdfDocumentObject) => PdfTask<boolean>;
2774
+ /**
2775
+ * Attempt to unlock owner permissions on an encrypted document.
2776
+ * Call this after opening a document with user-level access to gain full permissions.
2777
+ * @param doc - pdf document
2778
+ * @param ownerPassword - the owner password
2779
+ * @returns task that indicates whether unlock succeeded
2780
+ */
2781
+ unlockOwnerPermissions: (doc: PdfDocumentObject, ownerPassword: string) => PdfTask<boolean>;
2782
+ /**
2783
+ * Check if a document is encrypted.
2784
+ * @param doc - pdf document
2785
+ * @returns task that resolves to true if the document is encrypted
2786
+ */
2787
+ isEncrypted: (doc: PdfDocumentObject) => PdfTask<boolean>;
2788
+ /**
2789
+ * Check if owner permissions are currently unlocked.
2790
+ * @param doc - pdf document
2791
+ * @returns task that resolves to true if owner permissions are unlocked
2792
+ */
2793
+ isOwnerUnlocked: (doc: PdfDocumentObject) => PdfTask<boolean>;
2637
2794
  }
2638
2795
  /**
2639
2796
  * Method name of PdfEngine interface
@@ -2708,6 +2865,11 @@ export interface IPdfiumExecutor {
2708
2865
  saveAsCopy(doc: PdfDocumentObject): PdfTask<ArrayBuffer>;
2709
2866
  closeDocument(doc: PdfDocumentObject): PdfTask<boolean>;
2710
2867
  closeAllDocuments(): PdfTask<boolean>;
2868
+ setDocumentEncryption(doc: PdfDocumentObject, userPassword: string, ownerPassword: string, allowedFlags: number): PdfTask<boolean>;
2869
+ removeEncryption(doc: PdfDocumentObject): PdfTask<boolean>;
2870
+ unlockOwnerPermissions(doc: PdfDocumentObject, ownerPassword: string): PdfTask<boolean>;
2871
+ isEncrypted(doc: PdfDocumentObject): PdfTask<boolean>;
2872
+ isOwnerUnlocked(doc: PdfDocumentObject): PdfTask<boolean>;
2711
2873
  }
2712
2874
  /**
2713
2875
  * Arguments of PdfEngine method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/models",
3
- "version": "2.1.2",
3
+ "version": "2.3.0",
4
4
  "private": false,
5
5
  "description": "Shared type definitions, data models, and utility helpers (geometry, tasks, logging, PDF primitives) that underpin every package in the EmbedPDF ecosystem.",
6
6
  "type": "module",