【发布时间】:2017-03-27 09:24:29
【问题描述】:
我在我的项目中使用 pdf.js,但我遇到了加密 pdf 的问题。我正在使用 PDF.js 的密码回调函数来提供密码。
PDFJS.getDocument(file, null, passwordCB, null).then(function (res) {
console.log("Document Decrypted);
});
这里是密码回调函数
var passwordCB = function (passwordFunc, reason) {
if (reason === 1) {
passwordFunc(pdfpassword);
} else {
console.log("Wrong Password");
}
};
当密码错误时,控制不会退出passwordCB功能。在提供有效密码之前,它会卡住。
所以当用户输入错误密码时,我必须告诉他们密码错误,需要获取新密码。我没有使用默认的 javascript 提示符。
有没有办法打破 passwordCallback 函数并返回 getDocument() 承诺?
另外,从源代码中提到 passwordCallback 已被弃用。
* @param {function} passwordCallback (deprecated) It is used to request a
* password if wrong or no password was provided. The callback receives two
* parameters: function that needs to be called with new password and reason
* (see {PasswordResponses}).
还有其他方法可以为文档提供密码吗?关于这种情况的任何文章或示例?
【问题讨论】:
-
在github.com/mozilla/pdf.js/issues/7806 发帖——在那里回答。
-
这有点令人困惑。您有使用 passwordCallback 或 onPassword 回调处理 PDF 错误密码的示例吗?
标签: javascript pdf firefox mozilla pdf.js