Signing pdf file with multiple signatures

Hello,


I am working on adding more than signatures in a pdf file. The ultimate solution is to have subsquent certificates not invalidate the previous certificates.

The problem I have right now is that when I sign the file using Certificate A, then sign the file again with Certificate B, the Certificate A is invalidated, the information being "The file has changed since the last signing"

I would like to have a situation where I apply more than one certificate and have them valid.

Kindly let me know if this is something supported and how I can achieve it


Regards,

Pius

Hi Pius,


Thanks for contacting support and sorry for the delayed response.

In case you want to place several signatures, you must use approach specified below.

  1. Add empty signatures using DOM (as much as needed)
  2. Place signatures values in empty signatures using facade PdfFileSignature, each Sign/Save add one new signature.

[C#]

Document doc = new Document(@“input.pdf”);<o:p></o:p>

//place empty signatures

SignatureField s1 = new SignatureField(doc.Pages[1], new Rectangle(200, 200, 300, 100));

SignatureField s2 = new SignatureField(doc.Pages[2], new Rectangle(200, 200, 300, 100));

doc.Form.Add(s1);

doc.Form.Add(s2);

doc.Save("presign_output.pdf");

//create PdfFileSignature object and bind input and output PDF files

PdfFileSignature pdfSign = new PdfFileSignature(@"presign_output.pdf", @"sign_output.pdf");

//create any of the three signature types

PKCS1 signature1 = new PKCS1(@"test1.pfx", "test1");

signature1.Reason = "Signature Reason";

signature1.ContactInfo = "Contact";

signature1.Location = "Location";

PKCS1 signature2 = new PKCS1(@"test1.pfx", "test1");

signature2.Reason = "Signature Reason";

signature2.ContactInfo = "Contact";

signature2.Location = "Location";

//place first signature

pdfSign.Sign(s1.PartialName, signature1);

pdfSign.Save();

//place second signature

pdfSign = new PdfFileSignature(@"sign_output.pdf", @"sign_output.pdf");

pdfSign.Sign(s2.PartialName, signature2);

pdfSign.Save();

An other approach can be to use only PdfFileSignature in order to place several signatures. However you need to create new PdfFileSignature after each signing. See explanations in previous comment.

[C#]

//create PdfFileSignature object and bind input and output PDF files

PdfFileSignature pdfSign = new PdfFileSignature(@"input.pdf", @"sign_output2.pdf");

//create a rectangle for signature location

System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);

//create any of the three signature types

PKCS1 signature = new PKCS1(@"test1.pfx", "test1");

PKCS1 signature2 = new PKCS1(@"test1.pfx", "test1");

pdfSign.Sign(1, "Signature Reason", "Contact", "Location", true, rect, signature);

rect = new System.Drawing.Rectangle(200, 200, 300, 200);

//save output PDF file

pdfSign.Save();

pdfSign.Close();

pdfSign = new PdfFileSignature(@"sign_output2.pdf", @"sign_output2.pdf");

pdfSign.Sign(2, "Signature Reason", "Contact", "Location", true, rect, signature2);

//save output PDF file

pdfSign.Save();


In case you still face any issue, please share your input PDF and signature files, so that we can further look into this matter.

Thanks for your response, but when i do sign with two signature it shows that the file has been altered since the signing.


How can the two certificates be valid at the same time

Hi Pius,


Thanks for the feedback.

Have you tried using above shared code snippet to add multiple signatures at same time ? If you are encountering any issue, please share your resource PDF and signature files so that we can test the scenario in our environment.

Hello,


The code sample is not working for me. Kindly find the attached files with signature i am using and pdf.

Also attached are the of page 1 and 2 status of the signatures when i click on the them. The page one signature is invalidated by the second signature.

Sample code


Document doc = new Document(@"");
//place empty signatures
SignatureField s1 = new SignatureField(doc.Pages[1], new Aspose.Pdf. Rectangle(200, 200, 300, 100));
SignatureField s2 = new SignatureField(doc.Pages[2], new Aspose.Pdf.Rectangle(200, 200, 300, 100));
doc.Form.Add(s1);
doc.Form.Add(s2);
doc.Save(“presign_output.pdf”);
//create PdfFileSignature object and bind input and output PDF files
PdfFileSignature pdfSign = new PdfFileSignature(@“presign_output.pdf”, @“sign_output.pdf”);
//create any of the three signature types
PKCS1 signature1 = new PKCS1(@“C:\Certs\cert9.pfx”, “Test123”);
signature1.Reason = “Signature Reason”;
signature1.ContactInfo = “Pius”;
signature1.Location = “Nairobi”;
PKCS1 signature2 = new PKCS1(@“C:\Certs\cert8.pfx”, “Test123”);
signature2.Reason = “Signature Reason”;
signature2.ContactInfo = “Pius Bg”;
signature2.Location = “Newyork”;
//place first signature
pdfSign.Sign(s1.PartialName, signature1);
pdfSign.Save();
//place second signature
pdfSign = new PdfFileSignature(@“sign_output.pdf”, @“sign_output.pdf”);
pdfSign.Sign(s2.PartialName, signature2);
pdfSign.Save();

Thanks!

Would be glad to hear from you regarding this.

Hi Pius,


Thanks for sharing the resource files.

I have tested the scenario and have observed that when viewing double signed PDF file, a message of unknown signature appears when trying to validate the signatures present inside PDF file. However I am unable to notice invalid signature messages. For the sake of correction, I have logged this problem as PDFNEWNET-40288 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for your inconvenience.

For your reference, I have also attached the output file generated over my end. Please take a look.

hi, i have same issue. any idea?

Hi there,

Thanks for your interest in Aspose. As shared here in your another similar post, the “Signature validity is unknown” warning relates to your signature certificate. Please check this thread of Adobe support forum for more details.

Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNET-40288) have been fixed in Aspose.PDF for .NET 21.7.