We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issues with PDFFileInfo in checking Encrypted- password Protected Files

Hi,

I am using the below code for checking encrypted and password protected files. For encrypted files isPDFFile always return fals and isEncrypted throws an error:

PdfFileInfo is not initialized. Use constructors with parameters or properties for initialization.

It always sets tru for hasOpenPassword no matter what and always throws an invalid passwordexception for editPassword even if it the one of the region of the files are protected.

Is there a way to capture all these information for a pdf file.

if(fileInfo.isPdfFile()){
metaData.setMimeType(PDFMetadata.MIME_TYPE_PDF);
}

//File is Password protected for opening.
if(fileInfo.hasOpenPassword()){
metaData.setPasswordProtected(true);
}

//File is Password Protected for Editing.
if(fileInfo.hasEditPassword()){
metaData.setSecure(true);
}

//File is encrypted.
if(fileInfo.isEncrypted()){
metaData.setEncrypted(true);
}

Regards,

Hi Rajeev,


Thanks for contacting support.

I have tested scenario using one of my sample PDF files and as per my observations, correct password encryption information is being returned. Please take a look over following code snippet which I have used for testing purposes. Can you please share your input/source PDF file, so that we can test the scenario in our environment. We are sorry for this inconvenience.

[Java]

// instantiate FielInfo object<o:p></o:p>

com.aspose.pdf.facades.PdfFileInfo fileInfo = new com.aspose.pdf.facades.PdfFileInfo();

// bind source PDF file

fileInfo.bindPdf("c:/pdftest/table_Secured_output.pdf");

// print if source file is password encrypted

System.out.println("Is document encrypted = " + fileInfo.isEncrypted());

// determine if the password type for document is User

if(fileInfo.getPasswordType() == com.aspose.pdf.PasswordType.User );

// print password type information

System.out.println("Password type = "+ fileInfo.getPasswordType() + " (type = User)");

fileInfo = new com.aspose.pdf.facades.PdfFileInfo();

fileInfo.bindPdf("c:/pdftest/table_Secured_output.pdf", "user");

// print if document is encrypted

System.out.println("Document is encrypted = "+fileInfo.isEncrypted());

//determine if the password type for document is Owner

if(fileInfo.getPasswordType() == com.aspose.pdf.PasswordType.Owner );

//print password type information

System.out.println("Password type = "+ fileInfo.getPasswordType() + " (type = Owner)");

// print if document has open password specified

System.out.println("Document has Open Password = "+fileInfo.hasOpenPassword());

//print if document has edit password specified

System.out.println("Document has Edit Password = "+fileInfo.hasEditPassword());

fileInfo = new com.aspose.pdf.facades.PdfFileInfo();

fileInfo.bindPdf("c:/pdftest/table_Secured_output.pdf");

//print if document is encrypted

System.out.println("Document is encrypted = "+fileInfo.isEncrypted());

if(fileInfo.getPasswordType() == com.aspose.pdf.PasswordType.Inaccessible );

// print password type information

System.out.println("Password type = "+ fileInfo.getPasswordType() + " (type = Inaccessible)");

if(fileInfo.hasOpenPassword());

// Document has open password enable

System.out.println("Document has open password enabled = "+ fileInfo.hasOpenPassword());

try

{

boolean hasOwnerPassword = fileInfo.hasEditPassword();

System.out.println("When PasswordType is Inaccessible we can't read HasEditPassword property.");

}

catch (Exception e)

{

// write what we expect

}