How to protect PDF file with a password using nodejs? without using pdfq or any CLI commands, is that possible ?
im generating an html template to pdf using pdf-creator-node. the output of it, i want to protect it with password.
here is the initial code:
const fs = require("fs");
const pdfCreator = require("pdf-creator-node");
const data = require("./utils/data");
// Read the HTML template
const htmlTemplate = fs.readFileSync(
"./templates/html/template.html",
"utf8"
);
// Define the options for the PDF generation
const options = {
format: "A4",
orientation: "portrait",
};
// Compile the HTML template and generate the PDF
const document = {
html: htmlTemplate,
data, // Optional data to pass to the template
path: "output.pdf", // Specify the output file path
};
pdfCreator
.create(document, options)
.then((result) => {
console.log("PDF created successfully");
})
.catch((error) => {
console.error("Error creating PDF:", error);
});
pdf-creator-nodeis just a very light front end tonode-html-pdfwhich usesphantomjs, and that can't do passworded PDF according to stackoverflow.com/questions/33719673/…node-qpdf... assuming thats the same thing you specifically don't want to use (i.e.pdfq), then, no, I have no suggestions for another approach