Шифрование PDF с помощью C++

Заблокируйте PDF-файлы с помощью библиотеки Aspose.PDF с помощью C++.

Шифрование PDF-документа с помощью библиотеки C++

Чтобы зашифровать PDF-файл, мы будем использовать Aspose.PDF для C++ API, который представляет собой многофункциональный, мощный и простой в использовании API для работы с документами для платформы cpp. Откройте менеджер пакетов NuGet, найдите Aspose.pdf и установите. Вы также можете использовать следующую команду из консоли Package Manager.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Как зашифровать PDF с помощью C++


Вам понадобится Aspose.PDF для C++, чтобы попробовать код в своей среде.

  1. Откройте PDF-документ с помощью объекта Document.
  2. Создайте пароль для пользователя и владельца.
  3. Вызовите метод Document.Encrypt
  4. Сохраните 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");