Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created September 15, 2022 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/b82b3ea942058be7aa590127bbcc43a8 to your computer and use it in GitHub Desktop.
Save bjoerntx/b82b3ea942058be7aa590127bbcc43a8 to your computer and use it in GitHub Desktop.
public static void SignFields() {
using (ServerTextControl tx = new ServerTextControl()) {
tx.Create();
// create a signature field
SignatureField signatureField = new SignatureField(
new System.Drawing.Size(2000, 2000), "txsign", 10);
// set image representation
signatureField.Image = new SignatureImage("signature.svg", 0);
// insert the field
tx.SignatureFields.Add(signatureField, -1);
// create a digital signature (for each field, if required)
DigitalSignature digitalSignature = new DigitalSignature(
new System.Security.Cryptography.X509Certificates.X509Certificate2(
"textcontrolself.pfx", "123"), null, "txsign");
// apply the signatures to the SaveSettings
SaveSettings saveSettings = new SaveSettings() {
SignatureFields = new DigitalSignature[] { digitalSignature }
};
// export to PDF
tx.Save("signed_fields.pdf", StreamType.AdobePDF, saveSettings);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment