Check a file is password protected or not in java


#1

Hello,
How can i check whether a file(.docx, .rtf, .pdf,.xls, .xlsx etc) is password protected or not?
Can i get the java sample code?
Thanks!


#2

@dineshreddydepa,

I have observed your comments. For Aspose.Cells, please visit this documentation link to achieve your requirements. We will update you for Aspose.PDF and Aspose.Words soon.


#3

Thanks,
Can I also get sample code for ppt and pptx files?


#4

@dineshreddydepa

For Aspsoe.Slides, you need to load the password protected presentation and InvalidPasswordException is thrown upon loading a password protected presentation. You can then load the presentation in catch block using following code.

public static void TestLoadPassProtected()
{
    try
    {
        Presentation pres = new Presentation("C:\\Aspose Data\\PassPres.pptx");
    }
    catch (InvalidPasswordException e)
    {
        LoadOptions options = new LoadOptions();
        options.setPassword ("abc");
        Presentation pres = new Presentation("C:\\Aspose Data\\PassPres.pptx",options);
        boolean isEncrypted= pres.getProtectionManager().isEncrypted();
 
    }
}

In order to verify the protected PDF, I suggest you to please visit this documentation link on your end.