node.js - 使用 node-qpdf 加密 pdf 文件
问题描述
我正在尝试使用node-qpdf
我只是做了简单的:
Test.pdf 在 index.js 所在的目录中
var qpdf = require('node-qpdf');
var options = {
keyLength: 128,
password: 'test123',
restrictions: {
print: 'low',
useAes: 'y'
}
}
var localFilePath ='Test.pdf';
var outputFilePath ='test';
qpdf.encrypt(localFilePath, options, outputFilePath);
我收到如下错误:
运行:nodemon index.js
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
C:\Users\Rad\Desktop\node-qpdf-master\test\node_modules\node-qpdf\index.js:56
return callback(null, outputStream);
^
TypeError: callback is not a function
at Object.Qpdf.encrypt (C:\Users\Rad\Desktop\node-qpdf-master\test\node_modules\node-qpdf\index.js:56:16)
at Object.<anonymous> (C:\Users\Rad\Desktop\node-qpdf-master\test\index.js:13:6)
at Module._compile (internal/modules/cjs/loader.js:945:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
at Module.load (internal/modules/cjs/loader.js:798:32)
at Function.Module._load (internal/modules/cjs/loader.js:711:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
at internal/main/run_main_module.js:17:11
[nodemon] app crashed - waiting for file changes before starting...
解决方案
我认为他们没有更新文档,我阅读了他们的代码,您必须像这样放置outputFile
和更改您的代码options
。
var options = {
keyLength: 256,
password: '12345',
outputFile: '<your output name file>',
restrictions: {
modify: 'none',
extract: 'n'
}
var doc = await qpdf.encrypt(`${fileLocation}.pdf`, options)
推荐阅读
- r - ggplot比例条填充分类变量得到错误消息
- vim - 在 vim 中设置“后备”文件类型
- youcompleteme - YouCompleteMe 完成失败
- r - R:如何处理不想消失的替换字符
- css - 在 CSS 中,带逗号的 box-shadow 表示什么?
- javascript - 如何将 Mathrandom 添加到课程中
- python - Python ndarray dtype和缓冲区问题 - 它返回不同的值
- python - 如何使用python中的列表有效地对列表进行排序
- c++ - Magick::EnableOpenCL 返回 true 但没有效果
- docker - 一个 docker 容器的多个静态 IP