Skip to content

Instantly share code, notes, and snippets.

@bjoerntx

bjoerntx/test.cs Secret

Created July 5, 2023 14:09
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/b3f4e8c109afbb0a4ebe9cd42b985bd0 to your computer and use it in GitHub Desktop.
Save bjoerntx/b3f4e8c109afbb0a4ebe9cd42b985bd0 to your computer and use it in GitHub Desktop.
[HttpPost]
public string ExportPDF()
{
Stream inputStream = Request.InputStream;
inputStream.Position = 0;
StreamReader str = new StreamReader(inputStream);
string sBuf = str.ReadToEndAsync().Result;
TXTextControl.Web.MVC.DocumentViewer.Models.SignatureData data =
JsonConvert.DeserializeObject<TXTextControl.Web.MVC.DocumentViewer.Models.SignatureData>(sBuf);
byte[] bPDF;
// create temporary ServerTextControl
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
// load the document
tx.Load(Convert.FromBase64String(data.SignedDocument.Document), TXTextControl.BinaryStreamType.InternalUnicodeFormat);
FlattenFormFields(tx);
X509Certificate2 cert = new X509Certificate2(Server.MapPath("~/App_Data/textcontrolself.pfx"), "123");
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings()
{
CreatorApplication = "TX Text Control Sample Application",
//DigitalSignature = new TXTextControl.DigitalSignature(cert, null),
SignatureFields = new DigitalSignature[] {
new TXTextControl.DigitalSignature(cert, null, "txsign"),
new TXTextControl.DigitalSignature(cert, null, "txsign_init")}
};
// 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