Detecting Password Protection in Documents

I noticed that in Aspose.pdf for .NET there is functionality for checking if the file has been password protected.

LINK

Is there similar or comparable functionality available for java?

My company has recently acquired a license for document conversions but detecting possible password protection on files while processing them would also be very useful for our current development.

We would need to be able to do this for PDF files as well as power point, excel and word (slides, cells, and words).

Hi Tammy,

Yes, this feature is available in all of Java APIs. Please check http://www.aspose.com/docs/display/pdfjava/How+to+-+determine+if+the+source+PDF+is+password+protected for PDF. You can use the following code for Words, Cells and Slides respectively.

For Words:

com.aspose.words.FileFormatInfo wordInfo = com.aspose.words.FileFormatUtil.detectFileFormat("PasswordProtected.docx");

boolean isWordFileProtected = wordInfo.isEncrypted();

System.out.println(isWordFileProtected);

For Cells

com.aspose.cells.FileFormatInfo excelInfo = com.aspose.cells.FileFormatUtil.detectFileFormat("PasswordProtected.xlsx");

boolean isExcelFileProtected = excelInfo.isEncrypted();

System.out.println(isExcelFileProtected);

For Slides

try{

PresentationEx pres = new PresentationEx("PasswordProtected.pptx");

} catch (com.aspose.slides.InvalidPasswordException e) {

// TODO Auto-generated catch block

System.out.println("Document is password protected");

}

Best Regards,

Thank you for the response. That was exactly what I was looking for.


I have another question pertaining to the examples you provided.

What namespace does PresentationEx fall under? It doesn’t seem to exist under com.aspose.slides.

I did a little digging through your forums about PresentationEx and found a few responses from Aspose that said PresentationEx was to be used for .pptx while Presentation should be used for .ppt. The post also stated that there was a current effort to roll support for .pptx into Presentation so that it could be used for both.

These comments were a little less than a year old so is it also now safe to assume that Presentation does have support for .pptx at this time?
I’m using aspose.slides-14.10.0.jar

Hi Tammy,

Yes, you are right. That code is outdated now. This feature is available in the latest versions and you can use the following code for Aspose.Slides.

IPresentationInfo info = null;

info =com.aspose.slides.PresentationFactory.getInstance().getPresentationInfo("PasswordProtected.pptx");

System.out.println(info.isEncrypted());

Best Regards,