Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active April 28, 2020 07:23
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/48e02e7b3b384e7a0876a4a64559e9f8 to your computer and use it in GitHub Desktop.
Save bjoerntx/48e02e7b3b384e7a0876a4a64559e9f8 to your computer and use it in GitHub Desktop.
[HttpPost]
public string MergeDocument([FromBody] MergeDocument MergeDocument)
{
// create some merge data rows
List<Customer> lActualData = new List<Customer>() {
new Customer()
{
Company = "Text Control, LLC",
Firstname = "Tim",
Name = "Typer"
},
new Customer()
{
Company = "Text Control GmbH",
Firstname = "Bernie",
Name = "Bold"
}
};
byte[] baResults;
// create a new ServerTextControl instance to connect to MailMerge
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
// load the template
tx.Load(Convert.FromBase64String(MergeDocument.Document),
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// connect MailMerge
MailMerge mm = new MailMerge();
mm.TextComponent = tx;
// merge data into template
mm.MergeObjects(lActualData);
// save results
tx.Save(out baResults, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
}
return Convert.ToBase64String(baResults);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment