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. Image for the cookie policy date

Verify Pdf hasn't modified after adding signature?.

Hello,

I am using PDF component for adding digital signatures to the pdf document. 
Here is how I am adding the signature
   PdfLoadedDocument document = new PdfLoadedDocument("DigitalSignaturee2.pdf");
            PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;

            //Creates a signature field.

            PdfSignatureField signatureField = new PdfSignatureField(page, "SignatureField");

            signatureField.Bounds = new RectangleF(0, 0, 100, 100);

            signatureField.Signature = new PdfSignature(document, page, new PdfCertificate(@"C:\Users\Public\Documents\Syncfusion\ASP.NET MVC - EJ2\16.3.0.21\App_Data\PDF\PDF.pfx", "syncfusion"), "SignatureField");

            signatureField.Signature.Reason = "I am author of this document";

            document.Form.Fields.Add(signatureField);

            document.Save();
            //Closes the document
            document.Close(true);

I can get the document certificate as of volume 4 release. But how can I verify that document hasn't modified after the signature was added. 
Here is the code for the signature retrieval.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("DigitalSignaturee2.pdf");

            //Gets the page of the document

            PdfLoadedPage page1 = loadedDocument.Pages[0] as PdfLoadedPage;

         
            PdfLoadedSignatureField field2 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
         
            //Get PDF Certificate instance from signature field

            PdfCertificate certificate = field2.Signature.Certificate;

            //Get the certificate details

            string subjectName = certificate.SubjectName;
            string issuerName = certificate.IssuerName;

thanks
iosman

3 Replies

SL Sowmiya Loganathan Syncfusion Team November 7, 2019 04:11 AM

Hi iosman,  

Thank you for contacting Syncfusion support.  

We can verify whether PDF document has been modified or not by using “IsDocumentProperty” of PdfLoadedSignatureField. Please refer the below documentation link for more details, 

We have checked with the provided code snippet and noticed that you have adding the signature field to PDF form after adding the signature in it. While doing this resultant PDF get changed, so we have modified the code snippet and please find the same from below, 

//Load PDF document  
PdfLoadedDocument document = new PdfLoadedDocument("DigitalSignaturee2.pdf"); 
 
//Get loaded page 
PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; 
 
//Creates a signature field 
PdfSignatureField signatureField = new PdfSignatureField(page, "SignatureField"); 
 
//Add siganture  
signatureField.Bounds = new RectangleF(0, 0, 100, 100); 
signatureField.Signature = new PdfSignature(document, page, new PdfCertificate(@"PDF.pfx", "syn 
signatureField.Signature.Reason = "I am author of this document"; 
 
//Save the document  
document.Save(); 
//Closes the document 
document.Close(true); 
 
//Load the documet  
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("DigitalSignaturee2.pdf"); 
 
//Gets the page of the document 
PdfLoadedPage page1 = loadedDocument.Pages[0] as PdfLoadedPage; 
 
//Gets the first signature field of the PDF document. 
PdfLoadedSignatureField field2 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; 
 
//Validate signature and get the validation result 
PdfSignatureValidationResult result = field2.ValidateSignature(); 
 
//Get value whether document is modified or not  
bool isDocumentModified = result.IsDocumentModified; 


Please try the above sample in your end and let us know the result.  

Regards, 
Sowmiya Loganathan 



IM ios man replied to ios man November 10, 2019 10:53 PM

Hello,

I am using PDF component for adding digital signatures to the pdf document. 
Here is how I am adding the signature
   PdfLoadedDocument document = new PdfLoadedDocument("DigitalSignaturee2.pdf");
            PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;

            //Creates a signature field.

            PdfSignatureField signatureField = new PdfSignatureField(page, "SignatureField");

            signatureField.Bounds = new RectangleF(0, 0, 100, 100);

            signatureField.Signature = new PdfSignature(document, page, new PdfCertificate(@"C:\Users\Public\Documents\Syncfusion\ASP.NET MVC - EJ2\16.3.0.21\App_Data\PDF\PDF.pfx", "syncfusion"), "SignatureField");

            signatureField.Signature.Reason = "I am author of this document";

            document.Form.Fields.Add(signatureField);

            document.Save();
            //Closes the document
            document.Close(true);

I can get the document certificate as of volume 4 release. But how can I verify that document hasn't modified after the signature was added. 
Here is the code for the signature retrieval.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("DigitalSignaturee2.pdf");

            //Gets the page of the document

            PdfLoadedPage page1 = loadedDocument.Pages[0] as PdfLoadedPage;

         
            PdfLoadedSignatureField field2 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
         
            //Get PDF Certificate instance from signature field

            PdfCertificate certificate = field2.Signature.Certificate;

            //Get the certificate details

            string subjectName = certificate.SubjectName;
            string issuerName = certificate.IssuerName;

thanks
iosman

thanks for the information.



SS Sarasilmiya Shahul Hameed Syncfusion Team November 12, 2019 01:18 AM

Hi iosman, 
  
Most welcome. Please get back to us if you need further assistance. 
  
Regards, 
Sara 


Loader.
Live Chat Icon For mobile
Up arrow icon