Cifrar PDF mediante C++

Bloquee archivos PDF con la biblioteca Aspose.PDF mediante C++.

Cifrar documento PDF mediante la biblioteca C++

Para cifrar el archivo PDF, usaremos la API Aspose.PDF para C++, que es una API de manipulación de documentos rica en funciones, potente y fácil de usar para la plataforma cpp. Abra el administrador de paquetes NuGet, busque Aspose.pdf e instálelo. También puede usar el siguiente comando desde la consola de Package Manager.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Cómo cifrar PDF a través de C++


Necesitas Aspose.PDF for C++ para probar el código en tu entorno.

  1. Abra un documento PDF con el objeto Document.
  2. Crea una contraseña para el usuario y el propietario.
  3. Llame al métodoDocument.Encrypt.
  4. Guarde el archivo PDF.

<% encrypt.code-block.text %>

Cifrar documento 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");