Enkripsi PDF melalui C++

Kunci File PDF dengan Perpustakaan Aspose.PDF menggunakan C++.

Enkripsi Dokumen PDF Menggunakan C++ Library

Untuk mengenkripsi file PDF, kita akan menggunakan Aspose.PDF untuk C++ API yang merupakan API manipulasi dokumen yang kaya fitur, kuat dan mudah digunakan untuk platform cpp. Buka manajer paket nuget, cari Aspose.pdf dan instal. Anda juga dapat menggunakan perintah berikut dari Konsol Manajer Paket.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Cara Mengenkripsi PDF melalui C++


Anda perlu Aspose.PDF untuk C++ untuk mencoba kode di lingkungan Anda.

  1. Buka dokumen PDF menggunakan objek Dokumen.
  2. Buat kata sandi untuk pengguna dan pemilik.
  3. Panggil Document.Encrypt Metode.
  4. Simpan file PDF.

<% encrypt.code-block.text %>

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