Skip to content

Instantly share code, notes, and snippets.

@bjoerntx

bjoerntx/test.cs Secret

Created July 25, 2023 19:57
Show Gist options
  • Save bjoerntx/2ed6ca4584ba89539e6b8b8cb17d35ff to your computer and use it in GitHub Desktop.
Save bjoerntx/2ed6ca4584ba89539e6b8b8cb17d35ff to your computer and use it in GitHub Desktop.
[CustomActionFilter]
[HttpPost]
public IActionResult HandleSignature([FromBody] SignatureData data) {
byte[] bPDF;
// create temporary ServerTextControl
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// load the document
tx.Load(Convert.FromBase64String(data.SignedDocument.Document), TXTextControl.BinaryStreamType.InternalUnicodeFormat);
//FlattenFormFields(tx);
X509Certificate2 cert = new X509Certificate2("App_Data/textcontrolself.pfx", "123");
var signatureFields = new List<DigitalSignature>();
foreach (SignatureBox box in data.SignatureBoxes) {
signatureFields.Add(new DigitalSignature(cert, null, box.Name));
}
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
CreatorApplication = "Your Application",
SignatureFields = signatureFields.ToArray()
};
// store the PDF in the database or send it to the client
tx.Save(out bPDF, TXTextControl.BinaryStreamType.AdobePDFA, saveSettings);
// alternatively, save the PDF to a file
tx.Save("App_Data/signed.pdf", TXTextControl.StreamType.AdobePDFA, saveSettings);
}
// return any value to the client
return Ok();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment