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.문서 객체를 사용하여 PDF 문서를 엽니다. 1.사용자 및 소유자의 비밀번호를 생성합니다. 1.문서.암호화 메서드를 호출합니다. 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");