// Define the certificate which will be used for the signing.
X509Certificate2 certificate = new X509Certificate2(certificateFile, certificateFilePassword);
// The name of the signature must be unique. string signatureName = "SampleSignature";
// This is the Form XObject element that represents the contents of the signature field.
Form form = new Form();
form.FormSource = new FormSource();
form.FormSource.Size = new Size(220, 220);
// We will use the editor to fill the Form XObject.
FixedContentEditor formEditor = new FixedContentEditor(form.FormSource);
form.Position.Translate(10, 10);
using (Stream stream = File.OpenRead("signature.png"))
{
formEditor.DrawImage(stream, new Size(181, 102));
}// The Signature object is added to a signature field, so we can add a visualization to it.
SignatureField signatureField = new SignatureField(signatureName);
signatureField.Signature = new Signature(certificate);
// The widget contains the Form XObject and defines the appearance of the signature field.
SignatureWidget widget = signatureField.Widgets.AddWidget();
widget.Rect = new Rect(new Point(200, 600), new Size(100, 100));
widget.Border = new AnnotationBorder(10, AnnotationBorderStyle.Solid, null);
widget.Content.NormalContentSource = form.FormSource;
widget.RecalculateContent();
// The Widget class inherits from Annotation. And, as any other annotation, must be added to the respective collection of the page.
RadFixedDocument document = this.pdfViewer.Document;
RadFixedPage lastPage = document.Pages.Last();
lastPage.Annotations.Add(widget);
FixedContentEditor editor = new FixedContentEditor(lastPage);
editor.Position.Translate(lastPage.Size.Width - 200, lastPage.Size.Height - 200);
editor.DrawForm(form.FormSource);
document.AcroForm.FormFields.Add(signatureField);
widget.RecalculateContent();
widget.AppearanceCharacteristics.Background = new Telerik.Windows.Documents.Fixed.Model.ColorSpaces.RgbColor(255, 0, 0);
I am attaching the sample project I created to test this functionality as well. Please, feel free to modify it in a way closer to your scenario.
I hope this solves your case.
Regards,
Martin
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.