通过 JavaScript 解密 PDF

使用 JavaScript 使用 Aspose.PDF 库解锁 PDF 文件。

使用 JavaScript 库解密 PDF 文档

为了解密 PDF 文件,我们将使用 Aspose.PDF for .NET API,这是一款功能丰富、功能强大且易于使用的适用于 javascript-cpp 平台的文档处理 API。打开 NuGet 软件包管理器,搜索 aspose.pdf 然后安装。您也可以从软件包管理器控制台使用以下命令。

如何通过 JavaScript 解密 PDF


你需要 Aspose.PDF 库 才能在你的环境中试用代码。

1.使用文档对象打开 PDF 文档。 1.为用户和所有者创建密码。 1.调用文档.解密方法。 1.保存 PDF 文件。

<% decrypt.code-block.text %>

解密 PDF 文档-JavaScript。

<% decrypt.code-block.subtitle %>

Input file:

File not added

Password:

Output format:

Output file:

    var ffileDecrypt = function (e) {
        const file_reader = new FileReader();
        file_reader.onload = (event) => {
        /*decrypt a PDF-file with password is "owner" and save the "ResultDecrypt.pdf"*/
        const json = AsposePdfDecrypt(event.target.result, e.target.files[0].name, "owner", "ResultDecrypt.pdf");
        if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult;
        else document.getElementById('output').textContent = json.errorText;
        /*make a link to download the result file*/
        DownloadFile(json.fileNameResult, "application/pdf");
        };
        file_reader.readAsArrayBuffer(e.target.files[0]);
    };