通過JavaScript via C++加密 PDF

使用 JavaScript via C++鎖定帶有.PDF庫的“檔”。

使用 JavaScript via C++ 庫加密 PDF 文件

為了加密PDF檔,我們將使用[Aspose.PDF用於.NET](https://products.aspose.com/pdf/net)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於 javascript-cpp 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

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


您需要 [Aspose.PDF 庫](https://releases.aspose.com/pdf) 來嘗試環境中的代碼。

  1. 使用文件對象打開 PDF 文件。
  2. 為使用者和擁有者創建密碼。
  3. 呼叫「文件加密」 方法。
  4. 保存 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]);
  }