Opening a password protected pdf

PDF can be protected by
a) an owner password
b) a user password 
c) a)and b)

Currently the SyncFusion PDF toolkit allows me to bypass programmatically any permissions set in the pdf as soon as I provide the user password

My question is: if  I supply the user password, is there a way with SyncFusion  to find out if the PDF is also owner protected or not
Because if the PDF is owner protected, I will not allow my code to bypass the pdf permissions. 


For example, in iText, if I open a documentReader with a user password or an owner password, I can get my answer with
documentReader.IsOpenedWithFullPermissions
or in pdfSharp with
pdfsdoc.SecuritySettings.HasOwnerPermissions


Thank you.

3 Replies

KC Karthikeyan Chandrasekar Syncfusion Team October 11, 2018 12:43 PM UTC

Hi Alain, 
Yes, we can achieve this by using the below code snippet 

//Load the existing PDF document. 
PdfLoadedDocument ldoc = new PdfLoadedDocument("Barcode-protected.pdf", "password"); 
             
//Get owner password 
if(ldoc.Security.OwnerPassword != string.Empty) 
{ 
    Console.WriteLine("Document opened with full permission"); 
} 
else 
{ 
    Console.WriteLine("Document opened with partial"); 
} 


Below is the behavior of Essential PDF 
Password Type 
User Password 
(ldoc.Security.UserPassword) 
Owner Password 
(ldoc.Security.OwnerPassword) 
If Owner password and User Password is set to the PDF and opened the document with User password 
Returns User Password 
Returns Null 
If Owner password and User Password is set to the PDF and opened the document with Owner password 
Returns User Password 
Returns Owner Password 
If Owner password is set to the PDF 
Returns Null 
Returns Owner Password 
If User password alone is set to the PDF 
Returns User Password 
Returns Owner Password (Owner password is same as the user password; it allows user to full permission). 

Note: However, this code will not work due to some internal bug in our source. We will fix this and it will be included in our upcoming Vol-3 SP1 release, which is expected to be available in the last week of October. If you need the patch in prior to this, please create a new Direct-Trac incident
Regards, 
Karthikeyan 



AL Alain October 11, 2018 02:52 PM UTC

Thank you for looking into this issue.

Case #1, 2, 3 are currently OK

But Case #4 in your table "If User password alone is set to the PDF " 
syncfusion currently reports an empty ownerPassword 

So looking forward for your next release.

Many thanks !



KC Karthikeyan Chandrasekar Syncfusion Team October 12, 2018 09:30 AM UTC

You are welcome Alain. 


Loader.
Up arrow icon