I need to encrypt existing pdf file with password protected when the pdf file is tried to open it should ask for password please anyone provide solution without using qpdf in nodejs I need the solution for password protect pdf file using nodejs
If you're not willing to call out to a command line tool, you can do this with in pure JS with coherentpdf.js, which is AGPL-licensed: https://github.com/coherentgraphics/coherentpdf.js
For example (untested):
const coherentpdf = require('./coherentpdf.js');
var pdf = coherentpdf.fromFile('in.pdf', '');
var permissions = [coherentpdf.noEdit];
cpdf.toFileEncrypted(pdf, coherentpdf.aes256bitisofalse, permissions, 'ownerpw', 'userpw', false, false, 'out.pdf');