C++ 経由でPDFを暗号化

C++ を使用して、Aspose.PDF ライブラリで PDF ファイルをロックします。

C++ ライブラリを使用してPDFドキュメントを暗号化

PDFファイルを暗号化するために、cpp プラットフォーム用の機能豊富で強力で使いやすいドキュメント操作 API である Aspose.PDF for C++ API を使用します。NuGet パッケージマネージャーを開き、aspose.pdf を検索してインストールします。パッケージマネージャーコンソールから次のコマンドを使用することもできます。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

C++ 経由でPDFを暗号化する方法


ご使用の環境でコードを試すには Aspose.PDF for C++ が必要です。

1。Document オブジェクトを使用して PDF ドキュメントを開きます。 1。ユーザーと所有者のパスワードを作成します。 1。Document.Encrypt メソッドを呼び出します。 1。PDF ファイルを保存します。

<% encrypt.code-block.text %>

PDF ドキュメントを暗号化-C++。

<% encrypt.code-block.subtitle %>

Input file:

File not added

Password:

Output format:

Output file:

    // String for path name.
    String _dataDir("C:\\Samples\\");

    // Load a source PDF file
    auto document = MakeObject<Document>(_dataDir + u"input.pdf");

    // Instantiate Document Privileges object
    // Apply restrictions on all privileges
    auto documentPrivilege = DocumentPrivilege::get_ForbidAll();
    // Only allow screen reading
    documentPrivilege->set_AllowScreenReaders(true);
    // Encrypt the file with User and Owner password.
    // Need to set the password, so that once the user views the file with user
    // password,
    // Only screen reading option is enabled
    document->Encrypt(u"user", u"owner", documentPrivilege, CryptoAlgorithm::AESx128, false);
    // Save updated document
    document->Save(_dataDir + u"SetPrivileges_out.pdf");