Programatically know if a pdf document have digital signature's forbiden?

Hi ,

Is possible to detect when a user restricts digital signatures permissions ? I attached a document with this special flags sets but if compared with others documents, canno't get diferences in Security.Permissions enum. 

I need to know when I can not digitally sign a document in a developed way 

Thankds in advance,

Jordi  

Attachment: CapturesAdobeReader_e85ad321.rar

3 Replies

KC Karthikeyan Chandrasekar Syncfusion Team August 2, 2018 10:00 AM UTC

Hi Jordi, 
You can check if the PDF document is restricted for signing by using the below code snippet. 
PdfLoadedDocument ldDoc = new PdfLoadedDocument("SignedPDFDocument.pdf"); 
// Condition to check if adding signature is allowed 
if(ldDoc.Security.Permissions == (PdfPermissionsFlags.EditContent|PdfPermissionsFlags.EditAnnotations) 
    && !ldDoc.IsEncrypted) 
{ 
    // You can add signature 
} 
else 
{ 
    // Cannot add signature 
} 
Revert me back if you need any further assistance. 
Regards, 
Karthikeyan  



JB Jordi Burgas August 3, 2018 06:25 AM UTC

Hi Karthikeyan,

Thanks for your answer. 

I think something escapes us. The code that you propose to me in the 2 documents that I have proven the result is the same. But if I open acrobat reader I can see through the tools menu that one allows signing with certificates while the other does not. Attached capture the Reader and also attached the 2 documents in case you want to perform the same test. 

Thanks for the help!

Jordi 

Attachment: DataProblem_51dc9723.rar


KC Karthikeyan Chandrasekar Syncfusion Team August 3, 2018 05:16 PM UTC

Hi Jordi, 
We have analysed the both the documents which you have given. The document “SignAllowed.pdf” is a signable PDF and it can be determined using the code snippet below: 

PdfLoadedDocument ldDoc = new PdfLoadedDocument( "SignAllowed.pdf"); 
            // Condition to check if adding signature is allowed  
 
                  
if ((ldDoc.Security.Permissions == PdfPermissionsFlags.EditContent || ldDoc.Security.Permissions == PdfPermissionsFlags.EditAnnotations || ldDoc.Security.Permissions == PdfPermissionsFlags.Default) 
&& !ldDoc.IsEncrypted) 
{ 
                // You can add signature  
} 
else 
{ 
// Cannot add signature  
} 

Note: The second document which you have given “SignNotAllowed.pdf” is a XFA document and it cannot be  by default but it passes the above condition. This is due to the reason that we have no support to determine whether the document is XFA. So in case if a document is XFA we cannot determine if it can be signed or not. 

Please let us know if you need any further information in this. 
Regards, 
Karthikeyan 


Loader.
Up arrow icon