Posted by a ceTe Software moderator
Hello,
Any modifications to a signed document is supposed to invalidate the signature. When you fill a signed PDF form and save it, the signature will get invalidated by design. In this case you would need to revalidate the document by signing it again.
Currently our library is not capable of signing the signature fields that already exist on the PDF. If have control over the creation of original PDF, don’t include the signature field when you first generate it. When it is time to sign that PDF, just add a new signature field and sign it as shown below:
//Open the PDF.
PdfDocument pdf = new PdfDocument("PDFwithNoSignField.pdf");
MergeDocument document = new MergeDocument(pdf);
//Add a signature field, sign and save.
var lSignatureField = new ceTe.DynamicPDF.PageElements.Forms.Signature("sigfield", 50, 200, 200, 200);
document.Pages[0].Elements.Add(lSignatureField);
document.Sign("sigfield", new Certificate("cert path", "cert password"));
document.Draw("signed.pdf");
In case you do not have control over the incoming PDF and if it has a signature field, then you can remove that field and replace it with a new field and sign it as shown below:
//Open the PDF.
PdfDocument pdf = new PdfDocument("PDFwithSignField.pdf");
MergeDocument document = new MergeDocument(pdf);
//retrieve the properties of existing signature field.
PdfFormField sigField = pdf.Form.Fields["sigfield"];
float x = sigField.GetX(document.Pages[sigField.GetOriginalPageNumber()-1]);
float y = sigField.GetY(document.Pages[sigField.GetOriginalPageNumber()-1]);
float width = sigField.Width;
float height = sigField.Height;
//flag the old signature field to be removed.
document.Form.Fields["sigfield"].Output = FormFieldOutput.Remove;
//use the properties of old signature field to add a new signature field in its place, sign and save.
var lSignatureField = new ceTe.DynamicPDF.PageElements.Forms.Signature("newsigfield", x, y, width, height);
//var lSignatureField = new ceTe.DynamicPDF.PageElements.Forms.Signature("newsigfield", 50, 200, 200, 200);
lSignatureField.Font = Font.Helvetica;
document.Pages[0].Elements.Add(lSignatureField);
document.Sign("sigfield", new Certificate("cert path", "cert password"));
document.Draw("signed.pdf");
Thanks,
ceTe Software Support Team.