Created
October 30, 2023 13:26
-
-
Save bjoerntx/7df6ed6cd66cf8f16ab8151d1af49f72 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
private bool SaveSignedPDF(TXTextControl.Web.MVC.DocumentViewer.Models.SignatureData data, Envelope envelope) | |
{ | |
try | |
{ | |
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) | |
{ | |
tx.Create(); | |
tx.Load(Convert.FromBase64String(data.SignedDocument.Document), TXTextControl.BinaryStreamType.InternalUnicodeFormat); | |
var embeddedFile = new EmbeddedFile($"tx-hash_{data.UniqueId}.txt", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(envelope)), null) | |
{ | |
Relationship = "Data", | |
MIMEType = "application/json" | |
}; | |
X509Certificate2 cert = new X509Certificate2("App_Data/textcontrolself.pfx", "123"); | |
var saveSettings = new TXTextControl.SaveSettings | |
{ | |
EmbeddedFiles = new EmbeddedFile[] { embeddedFile }, | |
CreatorApplication = "TX Text Control Sample Application", | |
SignatureFields = new DigitalSignature[] | |
{ | |
new TXTextControl.DigitalSignature(cert, null, "txsign") | |
} | |
}; | |
var savePath = Path.Combine("App_Data/signed", $"{data.UniqueId}.pdf"); | |
Directory.CreateDirectory(Path.GetDirectoryName(savePath)); | |
tx.Save(savePath, TXTextControl.StreamType.AdobePDF, saveSettings); | |
} | |
return true; | |
} | |
catch (Exception) | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment