Node.js PDFKit Library Example to Encrypt PDF Documents With Password in Javascript on Command Line
const PDFDocument = require("pdfkit");
const fs = require("fs");
var options = {
userPassword: "123456",
}
// Create a document
const doc = new PDFDocument(options);
// Pipe its output somewhere, like to a file or HTTP response
// See below for browser usage
doc.pipe(fs.createWriteStream("output.pdf"));
doc.addPage()
// Finalize PDF file
doc.end();