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
close icon

How to add multiple visual digital signatures to a PDF without breaking existing signatures?

Dear all,

I want to write a program for digital signing of PDF/A files with digital certificates. The files are signed by multiple users. Each digital signature shall have a visual presentation on the first page. I am using the code below. When the second user signs the pdf file, the already existing signature is broken. I have not limited the document or certificate permissions. What is required for adding signatures without breaking existing ones?

Thanks for your support!

               PdfLoadedDocument document = new PdfLoadedDocument(System.Convert.FromBase64String(tDocObj.tPayload.strDocBase64));
                PdfCertificate cert = new PdfCertificate(selectedCertificate[0]);
                PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;
                // Position of signature box
                float ox = tDocObj.tPayload.afSignatureBox[0];
                float oy = page.Graphics.Size.Height - tDocObj.tPayload.afSignatureBox[1] - tDocObj.tPayload.afSignatureBox[3];
                float w = tDocObj.tPayload.afSignatureBox[2];
                float h = tDocObj.tPayload.afSignatureBox[3];

                PdfSignature signature = new PdfSignature(document, page, cert, "Signature" + DateTime.Now.ToString("yyyyMMdd HHmmssK"));
                signature.TimeStampServer = new TimeStampServer(new Uri("http://rfc3161timestamp.globalsign.com/advanced"));
                signature.DocumentPermissions = PdfCertificationFlags.AllowComments | PdfCertificationFlags.AllowFormFill;
                signature.Bounds = new RectangleF(ox, oy, w, h);
                signature.EnableValidationAppearance = false;
                signature.EnableLtv = true;
                signature.ContactInfo = "CONTACT";
                signature.LocationInfo = "LOCATION";
                signature.Reason = "REASON";

                string htmlText = String.Format("Digitally signed by{0}Date: {1}", selectedCertificate[0].GetNameInfo(X509NameType.SimpleName, false), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ssK"));

                PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlText, new PdfStandardFont(PdfFontFamily.Helvetica, 14), PdfBrushes.Black);
                richTextElement.TextAlign = TextAlign.Left;

                PdfTemplate template = new PdfTemplate(w, h);
                richTextElement.Draw(template.Graphics, new RectangleF(new PointF(0, 0), new SizeF(w, h)));

                PdfBitmap image = new PdfBitmap("Logo.png");


                //Draw the logo
                PdfGraphicsState state = template.Graphics.Save();
                template.Graphics.SetTransparency(0.1f);
                if (image.Height > template.Graphics.ClientSize.Height || image.Width > template.Graphics.ClientSize.Width)
                    template.Graphics.DrawImage(image, PointF.Empty, new SizeF(w, h));
                else
                    template.Graphics.DrawImage(image, 0, 0);
                template.Graphics.Restore(state);

                signature.Appearance.Normal.Graphics.DrawPdfTemplate(template, new PointF(0, 0));

                //Saves and closes the document.
                FileStream tOutStream = new FileStream(strTempOutFile, FileMode.Create);
                document.Save(tOutStream);
                document.Close(true);
                tOutStream.Close();


                     

Attachment: Syncfusion_a72dccd2.7z

7 Replies

SL Sowmiya Loganathan Syncfusion Team August 22, 2019 12:06 PM UTC

Hi Thorsten, 
 
Thank you for contacting Syncfusion support.  
 
We can add multiple signature in PDF document without breaking the existing one. Please refer the below links for more details, 


Please let us know if you need any further assistance on this. 

Regards, 
Sowmiya L 



TT Thorsten Twellmann September 11, 2019 12:44 PM UTC

In my use case the initial document does not contain form fields. It is automatically generated from a DOC file with a PDF printer softer and immediately signed by this PDF printer with a digital signature. Subsequently, human users have to place their signature on the cover page. The position is indicated by an appropriately designed cover page (table with full name and free space for the signature). Each user has to indicate where to place the signature by drawing a box. Can I use syncfusion for multiple signatures of the same PDF file without having to add form fields before (it should be possible somehow, you do this e.g. with Acrobat Reader)?

Thanks
Thorsten 


SL Sowmiya Loganathan Syncfusion Team September 12, 2019 12:45 PM UTC

Hi Thorsten, 

We can add multiple signature in PDF document(different location) without using signature fields. We have created the sample for the same and please find the downloaded link from below, 


Note: Please make ensure whether you have using licensed assemblies. If you are using trial version, it will invalidate the older signature because of adding watermark to PDF.  

Please try the above sample in your end and let us know if it satisfies your requirement.  

Regards, 
Sowmiya L 
 



TT Thorsten Twellmann September 22, 2019 06:43 PM UTC

Dear Sowmiya,

I was able to identify the line that causes the problem in my code. If you add the bold line to your code, the first signature is invalidated after adding the second signature:

...
PdfPageBase pageBase = loadedDocument1.Pages[0] as PdfPageBase;
PdfGraphics graphics2 = pageBase.Graphics;
...

I am using "graphics.Size.Height" for calculating the position and size of the box holding the visual presentation of the signature.

Do you have any idea why adding this line cause the problem?

Thanks
Thorsten


SL Sowmiya Loganathan Syncfusion Team September 23, 2019 12:22 PM UTC

Hi Thorstem, 

We have tried with the provided code snippet and we were able to see the first signature is invalidated after adding the second one. The reason for this issue is while parsing page graphics (get graphics from loaded page), we have reinitialize it. So it invalidated the existing signature and it is the behavior of our current architecture. We can overcome this behavior by get size from loaded page as like the below code snippet, 

//Get loaded page 
PdfLoadedPage loadedPage = loadedDocument1.Pages[0] as PdfLoadedPage; 
float height = loadedPage.Size.Height;             
 
//Creates a digital signature 
PdfSignature pdfSignature = new PdfSignature(loadedDocument1, loadedPage, pdfCert, "Signature2"); 
 
//Sets signature information 
pdfSignature.Bounds = new RectangleF(new PointF(100, 200), new SizeF(200, height)); 

Please try this solution in your end and let us know if it satisfies your requirement. 

Regards, 
Sowmiya L 



TT Thorsten Twellmann September 23, 2019 07:38 PM UTC

This solved my problem.
Thanks a lot!
Thorsten


SL Sowmiya Loganathan Syncfusion Team September 24, 2019 05:29 AM UTC

Hi Thorstem, 
 
Thank you for the update. We glad to know that your requirement is achieved. 
 
Regards, 
Sowmiya L 


Loader.
Live Chat Icon For mobile
Up arrow icon