Control Exception PDF File

Contents
[ ]

PdfFileSecurity class allows you to control exceptions. To do this, you need to set setAllowExceptions to false or true. If you set the operation to false, the result of decryptFile will return true or false depending on the correctness of the password.

If you set setAllowExceptions to true, then you can get the result of the operation using the try-catch operator.

    public static void ControlExceptionPDFFile() {
        PdfFileSecurity fileSecurity = new PdfFileSecurity();
        fileSecurity.bindPdf(_dataDir + "sample_encrypted.pdf");
        fileSecurity.setAllowExceptions(false);
        // Decrypt PDF document

        if (!fileSecurity.decryptFile("IncorrectPassword")) {
            System.out.println("Something wrong...");
            System.out.println("Last exception: " + fileSecurity.getLastException().getMessage());
        }
        fileSecurity.save(_dataDir + "sample_decrtypted.pdf");
    }