我需要使用密码保护在Node.js中加密现有的PDF文件,而不使用qpdf。

huangapple go评论86阅读模式
英文:

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');

huangapple
  • 本文由 发表于 2023年6月22日 16:49:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76530108.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定