How to determine if pdf is password protected?

Hi,

I'm using Syncfusion.Pdf.Parsing.PdfLoadedDocument in VB.NET to read a pdf document. I'd like to know how to know whether the document is password protected. I've seen that
Syncfusion.Pdf.Parsing.PdfLoadedDocument.Security
has a protected property called "Enabled" which seems to be exactly what I want... only it is friend. What is the correct way of determining if the pdf is password protected? I've tried reading the
Syncfusion.Pdf.Parsing.PdfLoadedDocument.Security.Permissions
property and comparing it to
Syncfusion.Pdf.Security.PdfPermissionsFlags.Default,
but it just doesn't feel right. Any help would be highly appreciated.

Thanks, Felix

3 Replies

GL George Livingston Syncfusion Team June 15, 2012 12:39 PM UTC

Hi Felix,

Thank you using Syncfusion products.

To identify whether a document is secured, try loading the document in PdfLoadedDocument without providing the password, this action would throw “PdfDocumentException”. This is the way to identify the whether a document is password protected or not.

Please try this and let us know if you have any concerns.

Thanks,

George



FK Felix Kozelsky June 19, 2012 06:43 AM UTC

Hello George,

thank you for the answer. I finally managed to test it out and I still have a problem with it. The way you suggested doesn't work with PDFs that are locked for editing and not locked for reading. I need to be able to determine if the PDF is password protected in any way.
I haven't tested it through to the details but PDF I'm using is protected from anything but printing.

I ended up with
Public Function IsPasswordProtectedPDF(FileName As String) As Boolean
    Try
      Dim pdfDoc As New Syncfusion.Pdf.Parsing.PdfLoadedDocument(FileName)
      If pdfDoc.Security.Permissions <> Syncfusion.Pdf.Security.PdfPermissionsFlags.Default Then
        Return True
      End If
    Catch ex As Syncfusion.Pdf.PdfDocumentException
      Return True
    Catch
      Return False
    End Try
    Return False
  End Function

which still employs comparing permissions to default. Is there a reason why the Security.Enabled property is friend accessible? Why can't it be Public Readonly?

Thank you for your time,
Felix


GL George Livingston Syncfusion Team June 25, 2012 03:53 AM UTC

Hi Felix,

Thank you for patience.

Please create a Direct-Trac incident to get the implementation of a property to identify whether the PDF document is protected or not.

Please let me know if you have any questions.

Regards,
Georeg


Loader.
Up arrow icon