Multiple Signatures on a Single PDF

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)

@pravin1972

Would please also share the sample code snippet (as requested earlier) that you are using to carry out the whole process? We will test the scenario in our environment and address it accordingly.

PS: However, as per Adobe Reader, any change to the signed PDF document will revoke the signature validations.

Version of the Aspose.pdf we are using.
Current Aspose.pdf Version is 21.9

Scenario
When we insert multiple signatures in a single pdf, only the last signature is shown as valid, and all the prior signatures appear as invalid (in the signature panel). For example, if there are two signatories and a ten-page pdf document, then when we place two signatures per page and total twenty signatures should be valid.

Code snippet
MemoryStream stream = new MemoryStream(pfxBytes);
PKCS7 signature = new PKCS7(stream, null);
try
{
PdfFileSignature pdfSign = new PdfFileSignature();
signature.ShowProperties = false;
if (SignonAllPage == 0) // Sign On all pages
{
int lpcount = strlist.Length;
PdfPageEditor pEdit = new PdfPageEditor();
pEdit.BindPdf(Destination);
for (int j = 0; j < lpcount; j++) // for loop for all pages for multiple signature
{
for (int PageCnt = 1; PageCnt <= NumberofPageInFile; PageCnt++)
{

                        double xpos = 0, ypos = 0; int pageNumber = 0;
                        string[] RectPos = strlist[j].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        pageNumber = Convert.ToInt32(RectPos[0]);
                        xpos = Convert.ToDouble(RectPos[1]);
                        ypos = Convert.ToDouble(RectPos[2]); 
                        PageSize size = pEdit.GetPageSize(pageNumber);
                        ypos = GetYPosition(size.Height, ypos);
                        xpos = GetXPosition(size.Width, xpos);
                        MemoryStream SignImagestream = new MemoryStream(ImageData); 
                        Bitmap bitMapImage = new System.Drawing.Bitmap(SignImagestream); 
                        bitMapImage = GetFinalImage(bitMapImage, UserName, "", EnvelopeId); 
                        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Convert.ToInt32(xpos), Convert.ToInt32(ypos), 140, 40); 
                        using (MemoryStream ms = new MemoryStream())
                        {
                            bitMapImage.Save(ms, ImageFormat.Png);
                            pdfSign.SignatureAppearanceStream = ms;
                            pdfSign.BindPdf(Destination);
                            pdfSign.Sign(PageCnt, true, rect, signature);
                            pdfSign.Save(Destination);
                        }
                        SignImagestream.Dispose();
                        SignImagestream.Flush();
                    }
                }
            }

Sample PDF
Attached Sample File

Please review and provide the resolution asap.

@rossjac

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-54595

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@asad.ali we are waiting for your response.
As you know its bug in your version, and you have fixed it in latest version. Can we get 21.9 version bug free? request you to take it on priority we are following you from 2-3 Month. Also suggest alternative options.

@pgkulkarni

The ticket is sadly not fully investigated yet due to other pending issues in the queue. However, we have recorded your concerns and we will surely consider them during ticket investigation process. Please note that we do value your concerns however, fixes to the reported issues are always made in the latest versions of the API. That is why we always recommend to use the latest version.

Please spare us some time to fully investigate the issue and share our feedback with you. We apologize for your inconvenience.