Check whether PDF is password protected

Hi ,

I am using Aspose.pdf.dll 9.1
Please find the attached pdf file and by using the below code it is return as the PDF is password protected.

public static bool IsPDFPasswordProtected(string FileName)
{

bool isPassProtected = false;

PdfFileInfo fileInfo = new PdfFileInfo(FileName);
return isPassProtected = fileInfo.IsEncrypted;

}

But i can able to open the pdf without password.

Can you please help me on this . Because it is urgent.

Regards
Anish

Hi Anish,


Thanks for your inquiry. A secured PDF file has two passwords, user password and owner password. Your PDF file has empty user password but owner password is set, so API is returning correct results. Please check attached image for the details, hopefully it will help.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,
But while opening the PDF it is directly opening with out asking the password.
So our customer is asking why it is problem while converting?

Regards
Anish

Hi,
Is there any way to avoid to check owner password while checking whether the file is protected?

Regards
Anish

anishvj:

But while opening the PDF it is directly opening with out asking the password.
So our customer is asking why it is problem while converting?


Hi Anish,

Thanks for you inquiry. I am afraid, It is PDF specification that a encrypted file can not be manipulated without passing owner password. To manipulate file you need to pass owner password while opening.

Document pdfDocument = new Aspose.Pdf.Document(myDir + "PasswordProtected.pdf","ownerpassword");

Best Regards,

anishvj:
Hi,
Is there any way to avoid to check owner password while checking whether the file is protected?

Regards
Anish

Hi Anish,

Thanks for your inquiry. Please check following code snippet, you can use HasOpenPassword and HasEditPasswordit would help you to accomplish the task.

But I am afraid if you skip checking owner password even then you will not be able to edit source document without passing owner password.

PdfFileInfo pdfFileInfo
= new PdfFileInfo(myDir+“Leonard Martin Guardian 2014.pdf”);<o:p></o:p>

if (pdfFileInfo.HasOpenPassword )

Console.WriteLine("The given PDF file is password protected and has open password.");

if (pdfFileInfo.HasEditPassword)

Console.WriteLine("The given PDF file is password protected and has owner password.");

Please feel free to contact us for any further assistance.


Best Regards,