PDF 파일 암호화
Contents
[
Hide
]
PDF 파일 암호화
비밀번호와 권한 규칙으로 PDF를 보호해야 하는 경우 PdfFileSecurity을 사용하세요.
단계
PdfFileSecurity인스턴스를 생성하세요.bindPdf으로 소스 PDF를 바인딩하세요.- 허용된 작업과 일치하는
DocumentPrivilege개체를 빌드하세요. - 필요한 키 크기와 알고리즘에 대해 적절한
encryptFile오버로드를 호출하세요. - 보안 파일을 저장하고 개체를 닫으세요.
자바 예제
public static void encryptPdfWithUserOwnerPassword(Path inputFile, Path outputFile) {
PdfFileSecurity fileSecurity = new PdfFileSecurity();
fileSecurity.bindPdf(inputFile.toString());
DocumentPrivilege privilege = DocumentPrivilege.getForbidAll();
privilege.setAllowPrint(true);
fileSecurity.encryptFile("user_password", "owner_password", privilege, KeySize.x128);
fileSecurity.save(outputFile.toString());
fileSecurity.close();
}
public static void encryptPdfWithPermissions(Path inputFile, Path outputFile) {
PdfFileSecurity fileSecurity = new PdfFileSecurity();
fileSecurity.bindPdf(inputFile.toString());
DocumentPrivilege privilege = DocumentPrivilege.getAllowAll();
privilege.setAllowPrint(false);
privilege.setAllowCopy(false);
fileSecurity.encryptFile("user_password", "owner_password", privilege, KeySize.x128);
fileSecurity.save(outputFile.toString());
fileSecurity.close();
}
public static void encryptPdfWithEncryptionAlgorithm(Path inputFile, Path outputFile) {
PdfFileSecurity fileSecurity = new PdfFileSecurity();
fileSecurity.bindPdf(inputFile.toString());
DocumentPrivilege privilege = DocumentPrivilege.getForbidAll();
privilege.setAllowPrint(true);
fileSecurity.encryptFile("user_password", "owner_password", privilege, KeySize.x256, Algorithm.AES);
fileSecurity.save(outputFile.toString());
fileSecurity.close();
}