Posted by a ceTe Software moderator
Hello,
The existing digital signature will be invalidated once you merge the existing PDF having signature in it. You will need to add new signature to the merged PDF document. Also please note that currently the DynamicPDF Merger API supports adding only one signature to the PDF document.
You can remove the form fields by flattening the PDF using FormFlattening property of the MergeDocument class. You will need to save the flattened PDF into byte array and then edit it using PdfDocument class constructor and create object. Then you can append PdfDocument object to MergeDocument object and add new signature to the PDF. Below is the sample code for it. Please note that flattening the PDF will remove all the form fields along with signature field.
MergeDocument tempDocument = new MergeDocument();
PdfDocument pdf = new PdfDocument(@"C:\Temp\Signature1.pdf");
tempDocument.Append(pdf);
//The below code removes all the form fields and faltten the PDF.
tempDocument.FormFlattening = FormFlatteningOptions.Default;
//Draw the PDF into byte array.
byte[] byteData = tempDocument.Draw();
//Edit the PDF to add new signature.
PdfDocument pdfObject = new PdfDocument(byteData);
MergeDocument finalDocument = new MergeDocument();
finalDocument.Append(pdfObject);
//Add new signature field.
Signature signature = new Signature("SigFieldNew", 10, 10, 250, 100);
//Below code to add signature field to first page.
finalDocument.Pages[0].Elements.Add(signature);
Certificate certificate = new Certificate(@"D:\JohnDoe.pfx", "dynamicpdf");
finalDocument.Sign("SigFieldNew", certificate);
//Save the final PDF.
finalDocument.Draw(@"C:\Temp\Output.pdf");
Thanks,
ceTe Software Support Team.