Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created November 1, 2022 22:03
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/c36aa92e21a50430dd00e84b35bd72f1 to your computer and use it in GitHub Desktop.
Save bjoerntx/c36aa92e21a50430dd00e84b35bd72f1 to your computer and use it in GitHub Desktop.
public IActionResult Index() {
// load the JSON data
string jsonData = System.IO.File.ReadAllText("App_Data/data.json");
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// load the template
tx.Load("App_Data/template.tx", TXTextControl.StreamType.InternalUnicodeFormat);
// use MailMerge to merge data
using (TXTextControl.DocumentServer.MailMerge mm =
new TXTextControl.DocumentServer.MailMerge()) {
mm.TextComponent = tx;
mm.MergeJsonData(jsonData);
}
// return result as HTML
string result = "";
tx.Save(out result, TXTextControl.StringStreamType.HTMLFormat);
ViewBag.Document = result;
}
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment