Encrypt PDFs
Set encryption options before finalizing the PDF. Use userPassword to require
a password to open the file and ownerPassword to control edit permissions.
var pdfDoc = new Recipe("input.pdf", "output.pdf");
pdfDoc
.encrypt({
userPassword: "open-password",
ownerPassword: "owner-password",
userProtectionFlag: 4,
})
.endPDF();
A Buffer source is encrypted the same way. endPDF() passes the encrypted
PDF to its callback, or writes it to the output path when one was given:
var pdfDoc = new Recipe(fs.readFileSync("input.pdf"));
pdfDoc.encrypt({ userPassword: "open-password" }).endPDF(function (pdfBuffer) {
// pdfBuffer holds the encrypted PDF.
});
Encryption options can also be supplied while creating a new Recipe document. See Change PDF Passwords for password replacement and encryption removal.