@@ -5,16 +5,13 @@ const EncryptDefaults = {
5
5
keyLength : 256 ,
6
6
overwrite : true ,
7
7
} ;
8
-
9
- export interface EncryptOptions {
8
+ type BaseYesNoOptions = "y" | "n"
9
+ type BasePrintOptions = "full" | "low" | "none"
10
+ interface BaseEncryptOptions {
11
+ /** Optional - Path to custom qpdf binary */
12
+ qpdfPath ?: string
10
13
/** The location of the unencrypted pdf file */
11
14
input : string ;
12
- /**
13
- * A number which defines the encryption algorithm to be used.
14
- * Using a keyLengh of 40 is insecure.
15
- * @default 256
16
- */
17
- keyLength ?: 40 | 128 | 256 ;
18
15
/** If defined, the output location of the encrypted pdf. If not defined, a Buffer will be returned. */
19
16
output ?: string ;
20
17
/**
@@ -27,36 +24,58 @@ export interface EncryptOptions {
27
24
* Optionally, an object containing `user` and `owner` for setting different roles.
28
25
* If undefined, will encrypt a pdf without requiring a password to decrypt
29
26
*/
30
- password ?:
31
- | string
32
- | {
33
- owner : string ;
34
- user : string ;
35
- } ;
27
+ password ?: string | {
28
+ owner : string ;
29
+ user : string ;
30
+ } ;
31
+ }
32
+ interface BaseRestrictionsOptions {
33
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-accessibility */
34
+ accessibility ?: BaseYesNoOptions ;
35
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-annotate */
36
+ annotate ?: BaseYesNoOptions ;
37
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-assemble */
38
+ assemble ?: BaseYesNoOptions ;
39
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-cleartext-metadata */
40
+ cleartextMetadata ?: boolean ;
41
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-extract */
42
+ extract ?: BaseYesNoOptions ;
43
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-form */
44
+ form ?: BaseYesNoOptions ;
45
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-modify */
46
+ modify ?: BaseYesNoOptions | "all" | "annotate" | "form" | "assembly" | "none" ;
47
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-modify-other */
48
+ modifyOther ?: BaseYesNoOptions ;
49
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-use-aes */
50
+ useAes ?: BaseYesNoOptions ;
51
+ }
52
+ interface Encrypt40bitOptions extends BaseEncryptOptions {
53
+ /**
54
+ * A number which defines the encryption algorithm to be used.
55
+ * Using a keyLengh of 40 is insecure.
56
+ * @default 256
57
+ */
58
+ keyLength ?: 40
36
59
/** Restrictions for the encrypted pdf */
37
60
restrictions ?: {
38
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-accessibility */
39
- accessibility ?: "y" | "n" ;
40
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-annotate */
41
- annotate ?: "y" | "n" ;
42
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-assemble */
43
- assemble ?: "y" | "n" ;
44
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-cleartext-metadata */
45
- cleartextMetadata ?: boolean ;
46
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-extract */
47
- extract ?: "y" | "n" ;
48
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-form */
49
- form ?: "y" | "n" ;
50
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-modify */
51
- modify ?: "y" | "n" | "all" | "annotate" | "form" | "assembly" | "none" ;
52
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-modify-other */
53
- modifyOther ?: "y" | "n" ;
54
61
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-print */
55
- print ?: "y" | "n" | "full" | "low" | "none" ;
56
- /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-use-aes */
57
- useAes ?: "y" | "n" ;
58
- } ;
62
+ print ?: BaseYesNoOptions | BasePrintOptions ;
63
+ } & BaseRestrictionsOptions ;
64
+ }
65
+ interface EncryptDefaultOptions extends BaseEncryptOptions {
66
+ /**
67
+ * A number which defines the encryption algorithm to be used.
68
+ * Using a keyLengh of 40 is insecure.
69
+ * @default 256
70
+ */
71
+ keyLength ?: 128 | 256 ;
72
+ /** Restrictions for the encrypted pdf */
73
+ restrictions ?: {
74
+ /** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-print */
75
+ print ?: BasePrintOptions ;
76
+ } & BaseRestrictionsOptions ;
59
77
}
78
+ export type EncryptOptions = Encrypt40bitOptions | EncryptDefaultOptions
60
79
61
80
/**
62
81
* Encrypts a PDF file
0 commit comments