【问题标题】:Unable to open password protected pdf in angular application无法在角度应用程序中打开受密码保护的 pdf
【发布时间】:2023-03-16 18:24:01
【问题描述】:

我在我的 Angular 应用程序中使用 pdfjs-dist 来呈现 pdf。但我无法打开受密码保护的 pdf。 有没有其他方法可以验证文档的密码并打开它。

【问题讨论】:

  • 请分享您的代码
  • 我使用 pdfjs-dist 的 getDocument 函数,比如 getDocument(fileData, null, '12345') 这里 '12345' 是我的 pdf 文件的密码
  • getDocument(fileData) 适用于普通 pdf,但无法打开受密码保护的 pdf

标签: angular pdf password-protection pdf.js pdfjs-dist


【解决方案1】:

使用下面的代码。

let  pdfJs= require('pdfjs-dist');
pdfJs.getDocument({ url: 'my.pdf', password: 'your password' }).then(function(pdf) 
{
  let text = [];
  for(let i = 1; i <= pdf.numPages; i++) {
    pdf.getPage(i).then(function(page) {
      page.getTextContent().then(function(data) {
        for(let j = 0; j < data.items.length; j++) {
          text.push(data.items[j].str);
        }        
      });
    });
  }

}).catch(function(error) {

});

【讨论】:

  • 现在我可以通过此代码打开受密码保护的文件selectedDoc.onPassword = function (validatePassword, reason) { let password; if (reason === 1) { password = prompt('enter a password:'); validatePassword(password); } else { password = prompt('Invalid! enter a password:'); validatePassword(password); } };
猜你喜欢
  • 2021-03-28
  • 1970-01-01
  • 1970-01-01
  • 2015-07-20
  • 2013-07-14
  • 2012-06-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多