Password protected pdf file

Hi Team,

In my application i am checking whether a pdf file is password protected or not.

After so much R&D i am using the following function to check this.
I know this is not a straight forward method. But this was working for all the type of pdf passwords.

The application is crashing at this point : info = new PdfFileInfo(FileName);

public static bool IsPDFPasswordProtected(string FileName)
{

// bool isPassProtected = false;

// PdfFileInfo fileInfo = new PdfFileInfo(FileName);
// // determine that source PDF file is Encrypted with password
// //if (fileInfo.IsEncrypted)
// //{
// // isPassProtected = true;
// //}
// //return isPassProtected;
//// return isPassProtected = fileInfo.IsEncrypted;



// if (fileInfo.HasOpenPassword || fileInfo.HasEditPassword)
// {
// isPassProtected = true;
// }

// return isPassProtected;


bool flag = false;
PdfFileInfo info = null;
try
{
info = new PdfFileInfo(FileName);
//if (info.HasOpenPassword)
//{
// flag = true;
//}
}
catch (IOException exception)
{
if (exception.Message.ToUpper().StartsWith(“BAD PASSWORD”))
{
flag = true;
}
}
catch (Exception exception2)
{
throw exception2;
}
finally
{
if (info != null)
{
try
{
info.ClearInfo();
info = null;
}
catch (Exception)
{
flag = true;
}

}
}
return flag;

}

But suddenly when i am processing the attached pdf file through this code my application is crashing.

Can you please help me on this ?
Regards
Anish

Hi Anish,


Thanks for your inquiry. I have tested your sample code with Aspose.Pdf for .NET 10.0.0 and unable to notice any issue. Please download and try latest version of Aspose.Pdf for .NET, it will resolve the issue.

Moreover, It seems there is some issue with your document. As when we open file in Adobe and move to second page it throws a error message, please find attached screenshot.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal Ahmad
May i know which version of Adobe you are using.
Because when i try to open this document in Adobe reader version (11.0.09) i am not facing this issue.

Regards
Anish

Hi Anish,


Thanks for your feedback. I am using Adobe Acrobat XI. You are right Adobe reader does not show any error on scrolling to second page of the document.

Best Regards,