@embedpdf/models 2.1.1 → 2.2.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
@@ -2054,15 +2067,53 @@ export interface PdfAnnotationTransformation {
2054
2067
  * @public
2055
2068
  */
2056
2069
  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
2070
+ /**
2071
+ * PDF permission flags per ISO 32000-1 Table 22
2072
+ * These are the flags to pass to setDocumentEncryption indicating what actions ARE ALLOWED.
2073
+ * Use buildPermissions() helper to combine flags.
2074
+ *
2075
+ * @public
2076
+ */
2077
+ export declare enum PdfPermissionFlag {
2078
+ /** Bit 3: Print (possibly degraded quality) */
2079
+ Print = 4,
2080
+ /** Bit 4: Modify document contents */
2081
+ ModifyContents = 8,
2082
+ /** Bit 5: Copy/extract text and graphics */
2083
+ CopyContents = 16,
2084
+ /** Bit 6: Add/modify annotations, fill forms */
2085
+ ModifyAnnotations = 32,
2086
+ /** Bit 9: Fill in existing form fields */
2087
+ FillForms = 256,
2088
+ /** Bit 10: Extract for accessibility */
2089
+ ExtractForAccessibility = 512,
2090
+ /** Bit 11: Assemble document (insert, rotate, delete pages) */
2091
+ AssembleDocument = 1024,
2092
+ /** Bit 12: High quality print */
2093
+ PrintHighQuality = 2048,
2094
+ /** Common combination: Allow all permissions */
2095
+ AllowAll = 3900
2096
+ }
2097
+ /**
2098
+ * Helper function to combine permission flags for setDocumentEncryption.
2099
+ * Note: PrintHighQuality automatically includes Print (enforced in C++ layer as well).
2100
+ *
2101
+ * @param flags - Permission flags to combine
2102
+ * @returns Combined permission flags as a number
2103
+ *
2104
+ * @public
2105
+ */
2106
+ export declare function buildPermissions(...flags: PdfPermissionFlag[]): number;
2107
+ /**
2108
+ * Error thrown when a permission check fails.
2109
+ *
2110
+ * @public
2111
+ */
2112
+ export declare class PermissionDeniedError extends Error {
2113
+ readonly requiredFlags: PdfPermissionFlag[];
2114
+ readonly currentPermissions: number;
2115
+ readonly name = "PermissionDeniedError";
2116
+ constructor(requiredFlags: PdfPermissionFlag[], currentPermissions: number);
2066
2117
  }
2067
2118
  export declare enum PdfPageFlattenFlag {
2068
2119
  Display = 0,
@@ -2634,6 +2685,43 @@ export interface PdfEngine<T = Blob> {
2634
2685
  * @returns task that all documents are closed or not
2635
2686
  */
2636
2687
  closeAllDocuments: () => PdfTask<boolean>;
2688
+ /**
2689
+ * Sets AES-256 encryption on a document.
2690
+ * Must be called before saveAsCopy() for encryption to take effect.
2691
+ * @param doc - pdf document
2692
+ * @param userPassword - Password to open document (empty = no open password)
2693
+ * @param ownerPassword - Password to change permissions (required)
2694
+ * @param allowedFlags - OR'd PdfPermissionFlag values indicating allowed actions
2695
+ * @returns task indicating success or failure
2696
+ */
2697
+ setDocumentEncryption: (doc: PdfDocumentObject, userPassword: string, ownerPassword: string, allowedFlags: number) => PdfTask<boolean>;
2698
+ /**
2699
+ * Marks document for encryption removal on save.
2700
+ * Call this to remove password protection when saving.
2701
+ * @param doc - pdf document
2702
+ * @returns task indicating success
2703
+ */
2704
+ removeEncryption: (doc: PdfDocumentObject) => PdfTask<boolean>;
2705
+ /**
2706
+ * Attempt to unlock owner permissions on an encrypted document.
2707
+ * Call this after opening a document with user-level access to gain full permissions.
2708
+ * @param doc - pdf document
2709
+ * @param ownerPassword - the owner password
2710
+ * @returns task that indicates whether unlock succeeded
2711
+ */
2712
+ unlockOwnerPermissions: (doc: PdfDocumentObject, ownerPassword: string) => PdfTask<boolean>;
2713
+ /**
2714
+ * Check if a document is encrypted.
2715
+ * @param doc - pdf document
2716
+ * @returns task that resolves to true if the document is encrypted
2717
+ */
2718
+ isEncrypted: (doc: PdfDocumentObject) => PdfTask<boolean>;
2719
+ /**
2720
+ * Check if owner permissions are currently unlocked.
2721
+ * @param doc - pdf document
2722
+ * @returns task that resolves to true if owner permissions are unlocked
2723
+ */
2724
+ isOwnerUnlocked: (doc: PdfDocumentObject) => PdfTask<boolean>;
2637
2725
  }
2638
2726
  /**
2639
2727
  * Method name of PdfEngine interface
@@ -2708,6 +2796,11 @@ export interface IPdfiumExecutor {
2708
2796
  saveAsCopy(doc: PdfDocumentObject): PdfTask<ArrayBuffer>;
2709
2797
  closeDocument(doc: PdfDocumentObject): PdfTask<boolean>;
2710
2798
  closeAllDocuments(): PdfTask<boolean>;
2799
+ setDocumentEncryption(doc: PdfDocumentObject, userPassword: string, ownerPassword: string, allowedFlags: number): PdfTask<boolean>;
2800
+ removeEncryption(doc: PdfDocumentObject): PdfTask<boolean>;
2801
+ unlockOwnerPermissions(doc: PdfDocumentObject, ownerPassword: string): PdfTask<boolean>;
2802
+ isEncrypted(doc: PdfDocumentObject): PdfTask<boolean>;
2803
+ isOwnerUnlocked(doc: PdfDocumentObject): PdfTask<boolean>;
2711
2804
  }
2712
2805
  /**
2713
2806
  * Arguments of PdfEngine method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/models",
3
- "version": "2.1.1",
3
+ "version": "2.2.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",