我需要加密现有的PDF文件与密码保护没有QPDF在NodeJS

2hh7jdfx  于 2023-06-29  发布在  Node.js
关注(0)|答案(1)|浏览(177)

我需要加密现有的PDF文件与密码保护的PDF文件时,试图打开它应该要求密码,请任何人提供解决方案,而不使用nodejs中的qpdf我需要使用nodejs密码保护PDF文件的解决方案

oo7oh9g9

oo7oh9g91#

如果你不愿意调用命令行工具,你可以用纯JS和coherentpdf.js来做,这是AGPL许可的: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');

相关问题