通过 JavaScript via C++ 加密 PDF

使用 JavaScript via C++ 使用 Aspose.PDF 库锁定 PDF 文件。

使用 JavaScript via C++ 库加密 PDF 文档

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

如何通过 JavaScript via C++ 加密 PDF


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

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

<% encrypt.code-block.text %>

加密 PDF 文档-JavaScript via C++。

<% encrypt.code-block.subtitle %>

Input file:

File not added

Password:

Output format:

Output file:


    var ffileEncrypt = function (e) {
        const file_reader = new FileReader();
        file_reader.onload = (event) => {
            /*encrypt a PDF-file with passwords "user" and "owner", and save the "ResultDecrypt.pdf"*/
        const json = AsposePdfEncrypt(event.target.result, e.target.files[0].name, "user", "owner", 
        Module.Permissions.PrintDocument, Module.CryptoAlgorithm.RC4x40, "ResultEncrypt.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]);
  }