A Content Preserving transformations on PDFs wrapped around QPDF
npm install node-qpdf-commonjsqpdf.
npm install node-qpdf2
`
Serverless?
This package can be uses on serverless platforms by using your vendor's layers functionality. Use the zip release from qpdf as the layer. For example, qpdf-11.1.0-bin-linux-x86_64.zip can be directly uploaded as a layer, and has been tested using Amazon Lambda.
Encryption
You can encrypt your PDF by following:
`
import { encrypt } from "node-qpdf2";
const pdf = {
input: "./test/example.pdf",
output: "/tmp/encrypted.pdf",
password: "1234",
}
await encrypt(pdf);
`
$3
Please see src/encrypt.ts for the latest options, as well as QPDF's documentation for information on what each restriction does.
$3
#### Render and Save:
`
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(options);
`
Decryption
You can decrypt your PDF by following:
`
import { decrypt } from "node-qpdf2";
const options = {
input: "/tmp/encrypted.pdf",
output: "/tmp/decrypted.pdf",
password: "YOUR_PASSWORD_TO_DECRYPT_PDF",
}
await decrypt(options);
`
PDF Encryption info
You can retrieve encryption information using the info function. This function will return a Promise. See here for more information.
`
import { info } from "node-qpdf2";
const options = {
input: "/tmp/encrypted.pdf",
password: "FILE_PASSWORD",
}
console.log(await info(options));
``