We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to determine if pdf is password protected?

Thread ID:





103951 Jun 11,2012 12:08 PM Jun 24,2012 11:53 PM ASP.NET Web Forms (Classic) 3
Tags: PDF
Felix Kozelsky
Asked On June 11, 2012 12:08 PM


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
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
property and comparing it to
but it just doesn't feel right. Any help would be highly appreciated.

Thanks, Felix

George Livingston [Syncfusion]
Replied On June 15, 2012 08:39 AM

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.



Felix Kozelsky
Replied On June 19, 2012 02:43 AM

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
      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
      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,

George Livingston [Syncfusion]
Replied On June 24, 2012 11:53 PM

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.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.