Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created March 20, 2024 09:22
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/b251cdf300e59091c1b70b86870a5a71 to your computer and use it in GitHub Desktop.
Save bjoerntx/b251cdf300e59091c1b70b86870a5a71 to your computer and use it in GitHub Desktop.
[HttpPost]
[Route("Sign")]
public string Sign([FromBody] SignatureData signatureData)
{
byte[] bPDF;
// create temporary ServerTextControl
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
// load the document
tx.Load(Convert.FromBase64String(signatureData.SignedDocument.Document),
BinaryStreamType.InternalUnicodeFormat);
// create a certificate
X509Certificate2 cert = new X509Certificate2("App_Data/textcontrol_self.pfx", "123");
// create a list of digital signatures
var signatureFields = new List<DigitalSignature>();
// create a digital signature for each signature box
foreach (SignatureBox box in signatureData.SignatureBoxes)
{
signatureFields.Add(new DigitalSignature(cert, null, box.Name));
}
// create save settings
SaveSettings saveSettings = new SaveSettings()
{
CreatorApplication = "Your Application",
SignatureFields = signatureFields.ToArray()
};
// save the document as PDF
tx.Save(out bPDF, BinaryStreamType.AdobePDFA, saveSettings);
}
// return as Base64 encoded string
return Convert.ToBase64String(bPDF);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment