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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to determine if pdf is password protected?

Thread ID:

Created:

Updated:

Platform:

Replies:

103951 Jun 11,2012 04:08 PM UTC Jun 25,2012 03:53 AM UTC ASP.NET Web Forms (Classic) 3
loading
Tags: PDF
Felix Kozelsky
Asked On June 11, 2012 04:08 PM UTC

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

George Livingston [Syncfusion]
Replied On 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


Felix Kozelsky
Replied On 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

George Livingston [Syncfusion]
Replied On 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


CONFIRMATION

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.

Warning Icon 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.Close Icon

;