Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created October 30, 2023 13:26
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/7df6ed6cd66cf8f16ab8151d1af49f72 to your computer and use it in GitHub Desktop.
Save bjoerntx/7df6ed6cd66cf8f16ab8151d1af49f72 to your computer and use it in GitHub Desktop.
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