PDF’yi C++ aracılığıyla şifreleyin

C++ kullanarak PDF Dosyalarını Aspose.PDF Kütüphanesi ile kilitleyin.

C++ Kullanarak PDF Belgesini Şifreleyin

PDF dosyasını şifrelemek için cpp platformu için zengin özelliklere sahip, güçlü ve kullanımı kolay bir belge işleme API’si olan Aspose.PDF for C++ API’sini kullanacağız. NuGet paket yöneticisini açın, Aspose.PDF öğesini arayın ve yükleyin. Paket Yöneticisi Konsolu’ndan aşağıdaki komutu da kullanabilirsiniz.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

PDF Nasıl Şifrelenir - C++


Ortamınızdaki kodu denemek için C++ için Aspose.PDF gerekir.

  1. Document nesnesini kullanarak bir PDF belgesi açın.
  2. Kullanıcı ve sahip için bir şifre oluşturun.
  3. ** Document.Encrypt** Yöntemini arayın.
  4. PDF dosyasını kaydedin.

<% encrypt.code-block.text %>

PDF Belgesini Şifrele - C++.

Bu örnek kod, PDF dosyasının nasıl şifreleneceğini gösterir - C++

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