Multiple Signatures on a Single PDF

Hi


I’m trying to find a way to sign a PDF document more than once in a single step. Currently, the only way I can find to sign a PDF is to use PdfFileSignature.Sign(). However, if I need to sign it more than once and I make a call to PdfFileSignature.Sign(), an ApplicationException with the message “Several signatures can’t be placed at once. Please, after each Sign invoke Save.” is thrown.

So can save in between each call (although it doesn’t really make sense). However, the big problem is that after the second sign and save is performed, it invalidates the first signature because the document has now been changed and my reader (Nitro, Foxit or Adobe Reader) tells me that the document has been altered since the signature was applied - thus defeating the purpose of signing.

We have a requirement to be apply multiple signatures to a document.

Please help.

Hi Ross,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the details.

rossjac:

However, if I need to sign it more than once and I make a call to PdfFileSignature.Sign(), an ApplicationException with the message "Several signatures can't be placed at once. Please, after each Sign invoke Save." is thrown.

Well, I tried signing a document with Adobe X and it also asks to save the document after the signature is added. So, it is the similar functionality in Aspose.Pdf for .NET as in Adobe X.

rossjac:
However, the big problem is that after the second sign and save is performed, it invalidates the first signature because the document has now been changed and my reader (Nitro, Foxit or Adobe Reader) tells me that the document has been altered since the signature was applied - thus defeating the purpose of signing.

I am able to regenerate your mentioned issue after an initial test. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-34147. You will be notified via this forum thread regarding any updates against this issue.

Sorry for the inconvenience,

We are having the same issue.

There are 2 issues here potentially:
1. we want to attach multiple images of initials and signatures on a multi-page document - this doesn’t seem to be supported in Aspose.Pdf but it supported in most (all?) other pdf signing applications
2. to get around the above issue we try sign multiple times (saving after each sign) - on signing the second time, when we open the document up in adobe it inidcates that we the original document has changed since the first signature was placed on. This seems to be in error.

p.

Hi Paul,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.Pdf.

pauldeg:
1. we want to attach multiple images of initials and signatures on a multi-page document - this doesn't seem to be supported in Aspose.Pdf but it supported in most (all?) other pdf signing applications


I am not clear about your requirement. As per my understanding, you have multiple signatures and you need to sign a PDF document with those multiple signatures. You require a method in which you can provide all the signatures at once and save the document one time. Please confirm if my understanding is correct, so we can further investigate this issue.

pauldeg:
2. to get around the above issue we try sign multiple times (saving after each sign) - on signing the second time, when we open the document up in adobe it inidcates that we the original document has changed since the first signature was placed on. This seems to be in error.

Please share your template PDF file and signature file with us to help us reproduce the issue at our end.

Sorry for the
inconvenience,

Hi Ross,


Thanks for your patience.

We have further investigated your requirement and as per you requirement, if you need to place several signatures, you must use a different approach (see code snippet below). In brief, you must

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

In your code snippet only sign document using the last Sign/Save methods, i.e. each time Sign/Save is called PdfFileSignature uses original input pdf, not previously signed/saved one.

[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();


Besides this, please note that you can use PdfFileSignature in order to place several signatures but in this case, you should 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();

The issues you have found earlier (filed as PDFNEWNET-34147) have been fixed in Aspose.Pdf for .NET 7.3.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

I am facing similar problem for Aspose.pdf for .net 11.2.0.0. I want to marge multiple pdf files which are having digital signature.
As per your suggestion i draw rectangle and add signature for those. But only last added signature gets validation others just plot the rectangles.
I also tried to remove exiting signatures and then draw rectangle and add signature for those but this also give same result.
Could you help me to add multiple signatures on a single PDF?

@Abhijeetk,
Please note, you cannot place multiple signatures at once, and you will invoke Save method after calling the Sign method of the PdfFileSignature class. Please refer to this help topic: Add Digital Signature in a PDF File. However, if this does not help, then kindly send us the complete details of the use case, including PDF document(s), security file and code snippet. We will investigate and share our findings with you.

Best Regards,
Imran Rafique

Hi Imran,

Thank you for your response.

I have attached zip file with contains code, test pfx files & two signed PDF files (output1 & output2). I want to marge these files in a single file with digital signature.

In Method1: i am simply applying the same signatures to merged file.
In Method2: 1) Remove existing signatures
2) Create Signature Fields
3) Add signature in Signature Field

Both method gives me same result. Only 2nd page signature gets validate and 1st page give error as ‘Signature invalid, document altered’.
use signature password as 000000

Please let me know if you required more details.

@Abhijeetk,
We are working over your query and will get back to you soon.

Best Regards,
Imran Rafique

@Abhijeetk,
We are facing the error of incorrect password for the source PFX files. Kindly send the code which you are using to utilize CorrespondeceSignature and PDFUtil classes (including passwords). We will investigate further and let you know about our findings. Your response is awaited.

Best Regards,
Imran Rafique

Please user password as ‘000000’.
I have modified the code, add pfx file path & password in CorrespondeceSignature object list.
Simply create object of PDFUtil class set the CorrespondeceSignatureList property and call marge function.

If required you can modify the code. I simply want to add signatures in merged file as they are in individual files.

@Abhijeetk,
We are working over your query and will get back to you soon.

Best Regards,
Imran Rafique

@Abhijeetk,
We managed to replicate the said error of invalid signature on the first page. It has been logged under the ticket ID PDFNET-43205 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates. We are sorry for the inconvenience caused.

Best Regards,
Imran Rafique

Hi Imran.
Is your development team get any solution on this?

@Abhijeetk,
The linked ticket ID PDFNET-43205 is pending for the analysis and not resolved yet. We will let you know once a significant progress has been made in this regard.

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

We have the similar problem, when we are trying to place multiple signature in pdf previous all signature get invalid and only last signature valid, we have tried this in latest Aspose version 23 also. Please give resolution asap as its affects our business requirement.

@pravin1972

The earlier logged ticket has been closed using below code snippet where you need to remove the broken signatures after adding multiple signatures:

var inputPdf1 = "Output1.pdf";
var inputPdf2 = "Output2.pdf";
var inputPfx1 = "Test1.pfx";
var inputPfx2 = "Test2.pfx";
var outputPdf_merged = "43205_merged.pdf";
var outputPdf = "43205.pdf";

var myPdfFileEditor = new PdfFileEditor();
var tempPDFs = new string[] { inputPdf1, inputPdf2 };
myPdfFileEditor.RemoveSignatures = true;            //Clear old broken signatures
myPdfFileEditor.Concatenate(tempPDFs, outputPdf_merged);

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

var pdfSign = new PdfFileSignature(new Aspose.Pdf.Document(outputPdf_merged));
var signature1 = new PKCS1(inputPfx1, "000000");
pdfSign.Sign(1, true, rect, signature1);
pdfSign.Save(outputPdf_merged);
pdfSign.Close();
pdfSign = new PdfFileSignature(new Aspose.Pdf.Document(outputPdf_merged));
var signature2 = new PKCS1(inputPfx2, "000000");
pdfSign.Sign(2, true, rect, signature2);
pdfSign.Save(outputPdf);
pdfSign.Close();

If this code does not suit your scenario, please share your sample code and sample PDF documents with us. We will test the scenario in our environment and address it accordingly.

Dear Asad,

Sorry for not writing back earlier. The issue is different with us. Below are the details for your reference:

SD3001419042023180249_Sign.pdf (2.21 MB)