تشفير ملف PDF
Contents
[
Hide
]
تشفير ملف PDF
استخدام PdfFileSecurity عندما تحتاج إلى حماية ملف PDF بكلمات مرور وقواعد الامتياز.
الخطوات
- أنشئ مثيلًا من
PdfFileSecurity. - اربط ملف PDF المصدر بـ
bindPdf. - ابنِ كائن
DocumentPrivilegeيطابق الإجراءات المسموح بها. - استدعِ المناسب
encryptFileتحميل زائد لحجم المفتاح والخوارزمية التي تحتاجها. - احفظ الملف المؤمَّن وأغلق الكائن.
أمثلة Java
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();
}