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 without asking the password.
So our customer is asking why it is problem while converting?

Hi Anish,

Thanks for your inquiry. I am afraid, It is The PDF specification states that an encrypted file cannot be manipulated without passing the owner password. To manipulate file you need to pass the owner password while opening.

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

Best Regards,

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

Regards,
Anish

Hi Anish,

Thanks for your inquiry. Please check the following code snippet. You can use HasOpenPassword and HasEditPassword; it would help you to accomplish the task.

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

PdfFileInfo pdfFileInfo = new PdfFileInfo(myDir + "Leonard Martin Guardian 2014.pdf");

if (pdfFileInfo.HasOpenPassword)
{
    Console.WriteLine("The given PDF file is password protected and has an open password.");
}

if (pdfFileInfo.HasEditPassword)
{
    Console.WriteLine("The given PDF file is password protected and has an owner password.");
}

Please feel free to contact us for any further assistance.

Best Regards,