1 回答
TA贡献1859条经验 获得超6个赞
这是一个工作代码示例:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf.worker.min.js"></script>
<script>
const pdfName = "empty-protected.pdf";
async function loaded()
{
const loadingTask = pdfjsLib.getDocument({ url: pdfName, password: "qwerty" });
loadingTask.promise.then(() => console.log(1, "OK"), (ex) => console.log(1, ex));
const loadingTask2 = pdfjsLib.getDocument({ url: pdfName, password: "" });
loadingTask2.promise.then(() => console.log(2, "OK"), (ex) => console.log(2, ex));
}
</script>
</head>
<body onload="javascript:loaded();">
</body>
</html>
qwerty
这是我用于实验的受密码保护的 pdf 文件(密码是):
https://mega.nz/file/lJg2GKgS#AdVJ0DZ1OfsGrlSqM67dfr_r2n8lBiiOm9q0o4wt7e4
包含pdf.worker.min.js
将警告更改"Warning: Deprecated API usage: No "GlobalWorkerOptions.workerSrc" specified."
为"Warning: Setting up fake worker."
添加回答
举报