Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit 2651a74

Browse files
committed
Organize permissions in option to an object
1 parent 6398cca commit 2651a74

2 files changed

Lines changed: 29 additions & 25 deletions

File tree

docs/getting_started.coffee.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,17 @@ settings in the `option` object when creating `PDFDocument`. By default, all ope
201201
You need to explicitly allow certain operations.
202202

203203
* `ownerPassword` - the owner password (string value)
204-
* `allowPrinting` - whether printing is allowed. Specify `"lowResolution"` to allow degraded printing, or `"highResolution"` to allow printing with high resolution
205-
* `allowModifying` - whether modifying the file is allowed. Specify `true` to allow modifying document content
206-
* `allowCopying` - whether copying text or graphics is allowed. Specify `true` to allow copying
207-
* `allowAnnotating` - whether annotating, form filling is allowed. Specify `true` to allow annotating and form filling
208-
* `allowFillingForms` - whether form filling and signing is allowed. Specify `true` to allow filling in form fields and signing
209-
* `allowContentAccessibility` - whether copying text for accessibility is allowed. Specify `true` to allow copying for accessibility
210-
* `allowDocumentAssembly` - whether assembling document is allowed. Specify `true` to allow document assembly
204+
* `permissions` - the object specifying PDF file permissions
205+
206+
Following settings are allowed in `permissions` object:
207+
208+
* `printing` - whether printing is allowed. Specify `"lowResolution"` to allow degraded printing, or `"highResolution"` to allow printing with high resolution
209+
* `modifying` - whether modifying the file is allowed. Specify `true` to allow modifying document content
210+
* `copying` - whether copying text or graphics is allowed. Specify `true` to allow copying
211+
* `annotating` - whether annotating, form filling is allowed. Specify `true` to allow annotating and form filling
212+
* `fillingForms` - whether form filling and signing is allowed. Specify `true` to allow filling in form fields and signing
213+
* `contentAccessibility` - whether copying text for accessibility is allowed. Specify `true` to allow copying for accessibility
214+
* `documentAssembly` - whether assembling document is allowed. Specify `true` to allow document assembly
211215
212216
You can specify either user password, owner password or both passwords.
213217
Behavior differs according to passwords you provides:
@@ -225,7 +229,7 @@ Behavior differs according to passwords you provides:
225229
226230
Note that PDF file itself cannot enforce access privileges.
227231
When file is decrypted, PDF viewer applications have full access to the file content,
228-
and it is up to them to respect permission settings.
232+
and it is up to viewer applications to respect permission settings.
229233

230234
To choose encryption method, you need to specify PDF version.
231235
PDFKit will choose best encryption method available in the PDF version you specified.

lib/security.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ class PDFSecurity {
8282
case 1:
8383
r = 2;
8484
this.keyBits = 40;
85-
permissions = getPermissionsR2(options);
85+
permissions = getPermissionsR2(options.permissions);
8686
break;
8787
case 2:
8888
r = 3;
8989
this.keyBits = 128;
90-
permissions = getPermissionsR3(options);
90+
permissions = getPermissionsR3(options.permissions);
9191
break;
9292
case 4:
9393
r = 4;
9494
this.keyBits = 128;
95-
permissions = getPermissionsR3(options);
95+
permissions = getPermissionsR3(options.permissions);
9696
break;
9797
}
9898

@@ -208,47 +208,47 @@ class PDFSecurity {
208208
}
209209
}
210210

211-
function getPermissionsR2(options) {
211+
function getPermissionsR2(permissionObject = {}) {
212212
let permissions = 0xffffffc0 >> 0;
213-
if (options.allowPrinting) {
213+
if (permissionObject.printing) {
214214
permissions |= 0b00000000010;
215215
}
216-
if (options.allowModifying) {
216+
if (permissionObject.modifying) {
217217
permissions |= 0b000000001000;
218218
}
219-
if (options.allowCopying) {
219+
if (permissionObject.copying) {
220220
permissions |= 0b000000010000;
221221
}
222-
if (options.allowAnnotating) {
222+
if (permissionObject.annotating) {
223223
permissions |= 0b000000100000;
224224
}
225225
return permissions;
226226
}
227227

228-
function getPermissionsR3(options) {
228+
function getPermissionsR3(permissionObject = {}) {
229229
let permissions = 0xfffff0c0 >> 0;
230-
if (options.allowPrinting === 'lowResolution') {
230+
if (permissionObject.printing === 'lowResolution') {
231231
permissions |= 0b000000000100;
232232
}
233-
if (options.allowPrinting === 'highResolution') {
233+
if (permissionObject.printing === 'highResolution') {
234234
permissions |= 0b100000000100;
235235
}
236-
if (options.allowModifying) {
236+
if (permissionObject.modifying) {
237237
permissions |= 0b000000001000;
238238
}
239-
if (options.allowCopying) {
239+
if (permissionObject.copying) {
240240
permissions |= 0b000000010000;
241241
}
242-
if (options.allowAnnotating) {
242+
if (permissionObject.annotating) {
243243
permissions |= 0b000000100000;
244244
}
245-
if (options.allowFillingForms) {
245+
if (permissionObject.fillingForms) {
246246
permissions |= 0b000100000000;
247247
}
248-
if (options.allowContentAccessibility) {
248+
if (permissionObject.contentAccessibility) {
249249
permissions |= 0b001000000000;
250250
}
251-
if (options.allowDocumentAssembly) {
251+
if (permissionObject.documentAssembly) {
252252
permissions |= 0b010000000000;
253253
}
254254
return permissions;

0 commit comments

Comments
 (0)