Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created January 27, 2022 11:14
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/4388124e3457b0a02f8f67f5cb6e55bd to your computer and use it in GitHub Desktop.
Save bjoerntx/4388124e3457b0a02f8f67f5cb6e55bd to your computer and use it in GitHub Desktop.
[HttpGet]
public IActionResult MergeDocument()
{
byte[] bDocument;
// create a ServerTextControl
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// load the template
tx.Load("App_Data/template.tx", TXTextControl.StreamType.InternalUnicodeFormat);
// create the mail merge engine
using (TXTextControl.DocumentServer.MailMerge mm = new TXTextControl.DocumentServer.MailMerge())
{
// connect to ServerTextControl instance
mm.TextComponent = tx;
// merge data
var jsonData = System.IO.File.ReadAllText("App_Data/data.json");
mm.MergeJsonData(jsonData);
}
// save in the internal format
tx.Save(out bDocument, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
}
return Ok(bDocument);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment