Created
September 21, 2022 19:16
-
-
Save bjoerntx/0170ca70926ca11dcf47dfaeb62611ea 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] | |
public string PDFSignSignatureFields(string document) { | |
byte[] bDocument; | |
// create temporary ServerTextControl | |
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) { | |
tx.Create(); | |
tx.Load(Convert.FromBase64String(document), BinaryStreamType.InternalUnicodeFormat); | |
X509Certificate2 cert = new X509Certificate2(Server.MapPath("~/App_Data/textcontrolself.pfx"), "123"); | |
List<DigitalSignature> digitalSignatures = new List<DigitalSignature>(); | |
foreach (SignatureField field in tx.SignatureFields) { | |
field.Name = Guid.NewGuid().ToString(); | |
digitalSignatures.Add(new DigitalSignature(cert, null, field.Name)); | |
field.Image = new SignatureImage(Server.MapPath("~/App_Data/Documents/signature.svg"), 4); | |
field.SignerData = new SignerData("Tim Typer", "Developer", "", "", "Online Demo"); | |
} | |
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() { | |
CreatorApplication = "TX Text Control Sample Application", | |
SignatureFields = digitalSignatures.ToArray() | |
}; | |
// export to PDF | |
tx.Save(out bDocument, BinaryStreamType.AdobePDF, saveSettings); | |
} | |
// return as Base64 encoded string | |
return Convert.ToBase64String(bDocument); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment