【问题标题】:Unable to decrypt PDF in node using node-qpdf无法使用 node-qpdf 在节点中解密 PDF
【发布时间】:2019-12-03 12:59:27
【问题描述】:

我们需要使用 node 解密受密码保护的 PDF 文件。 我们正在使用 node-qpdf。这是我们的场景。

1)。我们正在获取受密码保护的 PDF 文件作为输入。 2)。使用 QPDF 并使用可用密码,我们正在尝试对其进行解密。 3)。最后,我们得到了损坏的 PDF 文件。

我们正在关注给定的链接以供参考: 一种)。 https://www.npmjs.com/package/node-qpdf

在解密部分,我们可以看到以下代码:

var qpdf = require('node-qpdf');
qpdf.decrypt(localFilePath, 'YOUR_PASSWORD_TO_DECRYPT_PDF', outputFilePath);

localFilePath = './myInputFile_WithPassword.pdf'
YOUR_PASSWORD_TO_DECRYPT_PDF = 'test'
outputFilePath = './myoutfileWith_NopasswordProtection.pdf'

运行后我们得到的错误是:

TypeError: callback is not a function
at handleError (/home/runner/node_modules/node-qpdf/index.js:141:5)
at Socket.<anonymous> (/home/runner/node_modules/node-qpdf/index.js:124:5)
at Object.onceWrapper (events.js:286:20)
at Socket.emit (events.js:198:13)
at Socket.EventEmitter.emit (domain.js:448:20)
at addChunk (_stream_readable.js:287:12)
at readableAddChunk (_stream_readable.js:268:11)
at Socket.Readable.push (_stream_readable.js:223:10)
at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

对于回调问题,我们也尝试将代码更改为:

    qpdf.decrypt(localFilePath,'YOUR_PASSWORD_TO_DECRYPT_PDF', (res)=>{
    console.log(res);
    fs.createWriteStream(outputFilePath)       
     });

但得到错误:

"**Error: spawn qpdf ENOENT**"

我们也试过下面的代码:

============

var exec = require('child_process').exec;
var pdfsourcepath = './myInputFile_WithPassword.pdf'; 
var pdfdestinationpath = './myoutfileWith_NopasswordProtection.pdf'; 
var password = "test";  

var command = 'qpdf --decrypt --password='+password+' '+pdfsourcepath+' '+pdfdestinationpath+'';

exec(command, function (error){
if (error !== null){
console.log('exec error: ' + error);
 } 
else{
    console.log('Your pdf is decrypted successfully.');
    }
   }
 );

============

这段代码运行成功。

现在我们想使用节点模块 [node-qpdf] 完全实现相同的功能,但是 [如解释] 失败了。

请分享您对这个问题的想法。

我们也在 docker 镜像上实现了相同的功能,所以如果我们将 qpdf 安装在主服务器上,容器是否能够获取该二进制文件? 我已经检查了文章:https://hub.docker.com/r/mgodlewski/qpdf 但我有点困惑。

所以也分享一下 qpdf 的 docker 图像的分辨率。

【问题讨论】:

    标签: node.js encryption containers qpdf


    【解决方案1】:

    我认为只是删除回调参数。解密命令可能会返回解密文件的输出流。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-11
      • 1970-01-01
      • 2019-07-13
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-27
      相关资源
      最近更新 更多