How do determine if a PDF document is password protected

Hi,

Please give me a sample code to determine the PDF documents is password protected before loading the document into Aspose.PDF object.

Thanks,

Dhivya

Hi Dhivya,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

You may try Aspose.Pdf.Facades.PdfFileInfo class to get the information regarding a particular PDF file. You can use PdfFileInfo.IsEncrypted property to get your desired results. Please see the following link for more details and sample code regarding PdfFileInfo class.

http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/get-pdf-file-information-facades.html

Thank You & Best Regards,

Hi,

I am using Aspose.PDF.dll for .net version 6.3.0.0. I am getting System.NullReferenceException for below code.

PdfFileInfo fileInfo = new PdfFileInfo(fileName);

//Check if the document protected by password

if (fileInfo.IsEncrypted) // getting exception in this line code

{}

Thanks,

Dhivya

Hi Dhivya,

Please share your template PDF file with us. This will help us figure out the issue soon.

Thank You & Best Regards,

Hi,

I have attached sample PDF document for your reference.

Thanks,

Dhivya

Hi Dhivya,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the template file.

We have found your mentioned issue after an initial test. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-31695. You will be notified via this forum thread regarding any update against your issue.

Sorry for the inconvenience,

Hi Dhivya,

you may simply try using the following code snippet to get the information regarding PDF that either its encrypted or not. I have tested the scenario with upcoming release version of Aspose.Pdf for .NET 6.4.0 and the code seems to be working as expected. We are planning to release the new version in a day or two. Please be patient and wait for the new release.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

[C#]

PdfFileInfo fileInfo = new PdfFileInfo(@"D:\pdftest\Arabic12.pdf");
//Check if the document protected by password

if (fileInfo.IsEncrypted)
{
MessageBox.Show(fileInfo.IsEncrypted+"");
}

The issues you have found earlier (filed as 31695) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi


I have used isEncrypted property but it returns true even if there is no password in the PDF document.

Thanks,
-Surendra

Hi Surendra,

Thanks for contacting support.

A document will not only be encrypted if it is password protected. Please note that if there are other DocumentPreviliges are set then it will also set isEncrypted property as true. You may use following code snippet to check if any DocumentPrevilige has been set for the document.

Aspose.Pdf.Facades.PdfFileInfo info = new Aspose.Pdf.Facades.PdfFileInfo();

info.BindPdf("input.pdf");

var privilege = info.GetDocumentPrivilege();



In case of any further assistance please feel free to contact us.



Best Regards,

Andy.A.Kuan@wellsfargo.com:
Hi

I have used isEncrypted property but it returns true even if there is no password in the PDF document.
Hi Surendra,

Adding more to previous comments, the document may have document update/assembly password but it may not have document access/open password. But if you open the document properties, you may notice that Document is marked as encrypted.

In case of any related query, please share the input file, so that we can further look into this matter.