Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created February 6, 2024 11:36
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/aa3e73ff1c6a64d4a332f88966fa7f73 to your computer and use it in GitHub Desktop.
Save bjoerntx/aa3e73ff1c6a64d4a332f88966fa7f73 to your computer and use it in GitHub Desktop.
[ApiController]
[Route("signature")]
public class SignatureController : Controller
{
[HttpPost("SignDocument")]
public ActionResult SignDocument([FromBody] SignatureData signatureData)
{
byte[] bPDF;
// create temporary ServerTextControl
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
// load the document
tx.Load(Convert.FromBase64String(signatureData.SignedDocument.Document),
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// create a certificate
X509Certificate2 cert = new X509Certificate2("App_Data/textcontrolself.pfx", "123");
// assign the certificate to the signature fields
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings()
{
CreatorApplication = "TX Text Control Blazor Sample Application",
SignatureFields = new DigitalSignature[] {
new TXTextControl.DigitalSignature(cert, null, "txsign")
}
};
// save the document as PDF
tx.Save("App_Data/results_" + signatureData.UniqueId + ".pdf", TXTextControl.StreamType.AdobePDF, saveSettings);
}
return Ok();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment