Loading...

Check if PDF is password protected.

Support for GdPicture Light Imaging Toolkit and GdPicture Pro Imaging ActiveX/SDK.

Check if PDF is password protected.

Postby absoffthewake » Wed Dec 16, 2009 6:43 am

Is there a way to test if a PDF is password protected without prompting the user?

I would like to create a remove password function that would check if a PDF is password protected, and if it is, ask the user if they would like to remove the password.

It would work something like.

Open the PDF in the Viewer, you currently prompt the user for a password to open if it has a password. As you designed it, if the user enters the correct password, it opens the PDF.
After the PDF is opened, check if there is a password set for the PDF.
If there is, ask the user if they want to remove the password.
If user responds yes, create a new PDF without encryption or passwords, and import each page from password protected PDF.
Save New PDF.
absoffthewake
 
Posts: 31
Joined: Wed Jul 18, 2007 11:58 pm

Re: Check if PDF is password protected.

Postby Tom Moran » Thu Dec 17, 2009 1:32 am

Yes... you can turn off automatic password detection by setting PDFShowDialogforPassword property to False.

You can then manually check for a password like this:

GetStat = GdViewer1.DisplayFromPdfFile(NewFileName, PDFPassword)
'201 is the return code for password is present.
If GetStat = 201 Then
'here you'd display whatever you wish to get the password.

Once the file is open and can query the user to set a new password, delete password etc.

Tom
Tom Moran
 
Posts: 102
Joined: Thu May 24, 2007 9:41 am
Location: Phoenix, Arizona

Re: Check if PDF is password protected.

Postby absoffthewake » Thu Dec 17, 2009 5:41 am

Those functions must be in the new version as I'm using 5.11.18

Thanks!
absoffthewake
 
Posts: 31
Joined: Wed Jul 18, 2007 11:58 pm

Re: Check if PDF is password protected.

Postby absoffthewake » Thu Dec 17, 2009 5:49 am

Are there any functions to remove the password, or do I have to accomplish it as I mentioned in my first post? Thanks!
absoffthewake
 
Posts: 31
Joined: Wed Jul 18, 2007 11:58 pm

Re: Check if PDF is password protected.

Postby Tom Moran » Thu Dec 17, 2009 10:01 am

I am using the latest version, however, the GetStat method is not very new. It's been around for quite awhile. See the GdPictureStatus constants for details on all the codes.

You will not be able to open or manipulate a PDF password protected file unless you know the User Password. Once you have it open then you can change the password using the SaveAsPDFEx Method:

Imaging1.SaveAsPDFEx (sFilePath, sTitle, sAuthor, sSubject, sKeywords, sCreator, nPdfEncryption, nPDFRight, sUserpassWord, sOwnerPassword)

I believe you'll need to change the sFilePath when changing the password or removing the password. Remember to set the Encryption type as well. Also, with PDF, there are potentially two passwords; the User Password which is required to view the document and the Owner Password which is required to set permissions/rights (print, copy, etc). See PDFCreateRights method for details on setting permissions.

Tom
Tom Moran
 
Posts: 102
Joined: Thu May 24, 2007 9:41 am
Location: Phoenix, Arizona

Re: Check if PDF is password protected.

Postby absoffthewake » Thu Dec 17, 2009 4:15 pm

Much easier than saving it the old way!

Thanks!
absoffthewake
 
Posts: 31
Joined: Wed Jul 18, 2007 11:58 pm


Return to GdPicture [Pro] ActiveX

Who is online

Users browsing this forum: No registered users and 2 guests

cron