Created
March 20, 2024 09:22
-
-
Save bjoerntx/b251cdf300e59091c1b70b86870a5a71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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