Created
April 30, 2024 15:52
-
-
Save bjoerntx/358387261fbeaab959a4c24604a571a3 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 CreatePdf([FromBody] TXTextControl.Web.MVC.DocumentViewer.Models.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); | |
FlattenFormFields(tx); | |
// 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 Sample Application", | |
SignatureFields = new DigitalSignature[] { | |
new TXTextControl.DigitalSignature(cert, null, "txsign") | |
} | |
}; | |
// save the document as PDF | |
tx.Save(out bPDF, TXTextControl.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