Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparticuz committed Sep 14, 2021
1 parent d502252 commit dba4fa3
Showing 1 changed file with 47 additions and 28 deletions.
75 changes: 47 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,48 @@ You can encrypt your PDF by following:
```
import { encrypt } from "node-qpdf2";
const options = {
keyLength: 256,
password: 'YOUR_PASSWORD_TO_ENCRYPT'
const pdf = {
input: "./test/example.pdf",
output: "/tmp/encrypted.pdf",
password: "1234",
}
await encrypt(localFilePath, options, outputFilePath);
await encrypt(pdf);
```

### Options for Encryption
The following are **required options**
* `keyLength:` - a number which defines the encryption algorithm to be used. Values can be **40, 128 and 256** only.
* `password:` - a string containing the secret password which will be further used to unlock the PDF or an object containing `user` and `owner` for setting password for different roles.

```
interface EncryptOptions {
// This is the location of the unencrypted pdf;
input: string;
// A number which defines the encryption algorithm to be used. Values can be **40, 128 and 256** only. Defaults to 256
keyLength?: number;
// If defined, the file location of the encrypted pdf, if not defined, encrypt() will return a Buffer.
output?: string;
// If defined, will determine if the encrypted pdf will overwrite an existing file. Defaults to True
overwrite?: boolean;
// a string containing the secret password which will be further used to unlock the PDF or an object containing `user` and `owner` for setting password for different roles.
password?: string | {
owner: string;
user: string;
};
// See below
restrictions?: {
accessibility?: "y" | "n";
annotate?: "y" | "n";
extract?: "y" | "n";
modify?: "y" | "n" | "all" | "annotate" | "form" | "assembly" | "none";
print?: "y" | "n" | "full" | "low" | "none";
useAes?: "y" | "n";
};
}
```
You might want to set other options for each encryption algorithm inside `restrictions:` according to the `keyLength` you choose :-

*Key Length:* **40**
Expand Down Expand Up @@ -72,41 +101,31 @@ You might want to set other options for each encryption algorithm inside `restri
import { encrypt } from "node-qpdf2";
const options = {
input: "./test/example.pdf",
keyLength: 128,
output: "/tmp/encrypted.pdf",
password: 'YOUR_PASSWORD_TO_ENCRYPT',
restrictions: {
print: 'low',
useAes: 'y'
}
}
await encrypt(inputFilePath, options, outputFilePath);
```
or
```
import { encrypt } from "node-qpdf2";
const options = {
keyLength: 40,
password: {
user: 'YOUR_PASSWORD_TO_ENCRYPT_FOR_USER',
owner: 'YOUR_PASSWORD_TO_ENCRYPT_FOR_OWNER'
},
restrictions: {
print: 'low',
useAes: 'y'
}
};
await encrypt(inputFilePath, options, outputFilePath);
await encrypt(options);
```

## Decryption
You can decrypt your PDF by following:
```
import { decrypt } from "node-qpdf2";
await decrypt(inputFilePath, 'YOUR_PASSWORD_TO_DECRYPT_PDF', outputFilePath);
const options = {
input: "/tmp/encrypted.pdf",
output: "/tmp/decrypted.pdf",
password: "YOUR_PASSWORD_TO_DECRYPT_PDF",
}
await decrypt(options);
```

## Meta
Expand Down

0 comments on commit dba4fa3

Please sign in to comment.