I want to check if a pdf file is password protected or not to view. That is i want to know if the pdf file has user password or not.
I found some help in some forum
Just in case it ends up helping someone, here's a simple solution I have been using in vb.net. The problem with checking with fullpermissions (As mentioned above) is that you can't actually open a PDF that has a password that prevents you from opening it. I also have something I do about check for that in the code below. itextsharp.text.pdf has a few exceptions you might find useful actually, check it out if this isn't doing what you need.
Dim PDFDoc As PdfReader
Try
PDFDoc = New PdfReader(PDFToCheck)
If PDFDoc.IsOpenedWithFullPermissions = False Then
'PDF prevents things but it can still be opened. e.g. printing.
end if
Catch ex As iTextSharp.text.pdf.BadPasswordException
'this exception means the PDF can't be opened at all.
Finally
'do whatever if things are normal!
End Try