Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jul 18, 2016 5:16 pm

Hi,
Maybe it is a dumb question but I can't find anything in the program-guide:
Is there a way to know if a pdf is encrypted?

Thanks.

obrossard
 
Posts: 9
Joined: Wed Jul 13, 2016 8:41 pm

Tue Jul 19, 2016 3:13 am

Hi,

Thanks for your inquiry.
Did you mean you want to know if the PDF is encrypted with password ? If so, there is a way can check it. When you open a file without a password(LoadFromFile(string filename)) but this file has the password, it will throw an exception "can not open an encrypted document. The password is invalid". You can catch the exception and that means the file is encrypted with password.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Jul 19, 2016 12:14 pm

Yes I would like to know if a PDF is encrypted with a password. But when I open a file that has a password but only for some operation like edit content, I can open the file without the password but the file is still encrypted.

I tried to use the flags (Spire.Pdf.Security.PdfPermissionsFlags) but witouth success since the "default" flag is always present even if the document is encrypted.

obrossard
 
Posts: 9
Joined: Wed Jul 13, 2016 8:41 pm

Wed Jul 20, 2016 2:37 am

Hi,

Thanks for your reply.
The flags (Spire.Pdf.Security.PdfPermissionsFlags) can check if the document is encrypted, I have tested a document which only allows AccessibilityCopyContent with Spire.PDF V3.7.106,it returns correct value. I have attached the document and the flags image, please check. And could you please provide us your sample document which is encrypted but returns "default" flags to help us do an investigation ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Jul 20, 2016 1:03 pm

Hi,
Here is the code I used:
Code: Select all
               using (Spire.Pdf.PdfDocument document = new Spire.Pdf.PdfDocument(bytes))
                {
                    var flags = document.Security.Permissions;
                    var hasDefault = document.Security.Permissions.HasFlag(Spire.Pdf.Security.PdfPermissionsFlags.Default);
                }


For every documents I tried, even the one you provided in your last post, "hasDefault" always return true.
I have attached a document that is protected and that contain "Default" in the variable flags.

Edit: Is there another way to find if a document is encrypted?

obrossard
 
Posts: 9
Joined: Wed Jul 13, 2016 8:41 pm

Thu Jul 21, 2016 4:02 am

Hi,

Thanks for your feedback.
The method HasFlag isn't used to test if a document is encrypted.
We have added the new feature that can test if a document is encrypted directly, once there is any progress, we will inform you. Sorry for inconvenience cuased by this issue.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Jul 21, 2016 12:19 pm

Thank you! I can't wait for this new feature!

obrossard
 
Posts: 9
Joined: Wed Jul 13, 2016 8:41 pm

Fri Jul 22, 2016 1:44 am

Hi,

Thanks for your reply.
I just got information from our Dev team that the feature can be done and testing in next Monday. If the test passes, we will provide you a hotfix immediately.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon Jul 25, 2016 8:30 am

Hi,

Thanks for waiting.
Now the new feature has been done, welcome to test following hotfix.
http://www.e-iceblue.com/downloads/Temp ... .7.162.zip
Also, here is sample code for your reference.
Code: Select all
//true means it is encrypted
bool value = PdfDocument.Security.IsEncrypted;

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon Jul 25, 2016 2:35 pm

Thank you!
I made some quick tests and I found a document that is encrypted but the method return false. Here it is in attachment.

obrossard
 
Posts: 9
Joined: Wed Jul 13, 2016 8:41 pm

Tue Jul 26, 2016 1:43 am

Hi,

Thanks for your feedback.
I have noticed this issue and posted it to our Dev team. We will inform you when it is fixed. Sorry for inconvenience.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Jul 29, 2016 7:38 am

Hi,

Thanks for your waiting.
Now the issue has been fixed, welcome to test the following hotfix.
http://www.e-iceblue.com/downloads/Temp ... .7.168.zip
Also, we have changed the code to check if a document is encrypted, please try to use this method.
Code: Select all
bool value =PdfDoucment.IsEncrypted;


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Jul 29, 2016 12:43 pm

Hi,
The hotfix succeed our tests!
Thank you!

obrossard
 
Posts: 9
Joined: Wed Jul 13, 2016 8:41 pm

Mon Aug 01, 2016 1:24 am

Hi,

Thanks for your feedback.
Please feel free to contact us if there is any question. We are here for help.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF

cron