英文:
I need to encrypt existing pdf file with password protect without qpdf in nodejs
问题
我需要使用Node.js对现有的PDF文件进行加密,并设置密码保护。当尝试打开PDF文件时,应该会要求输入密码。请有人提供在Node.js中实现密码保护PDF文件的解决方案,但不要使用qpdf。
英文:
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
答案1
得分: 0
如果您不想调用命令行工具,可以使用纯JS来完成这个操作,使用AGPL许可的coherentpdf.js库:https://github.com/coherentgraphics/coherentpdf.js
例如(未经测试):
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');
英文:
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');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论