//decryption requires additional libraries
public static void decryptPDFN(PDDocument document, String password) throws
IOException, CryptographyException, BadSecurityHandlerException {
if (document.isEncrypted()) {
DecryptionMaterial decryptionMaterial = new StandardDecryptionMaterial(password);
document.openProtection(decryptionMaterial);
} else {
throw new RuntimeException("Document not encrypted");
}
}