Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created October 2, 2023 13:15
Show Gist options
  • Save bjoerntx/d56ec86c9cd1d256e469b8a16477306d to your computer and use it in GitHub Desktop.
Save bjoerntx/d56ec86c9cd1d256e469b8a16477306d to your computer and use it in GitHub Desktop.
public IActionResult Index()
{
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
// adding static text
TXTextControl.Selection sel = new TXTextControl.Selection();
sel.Text = "Welcome to Text Control\r\n";
sel.Bold = true;
tx.Selection = sel;
// adding merge fields
TXTextControl.DocumentServer.Fields.MergeField mergeField =
new TXTextControl.DocumentServer.Fields.MergeField()
{
Text = "{{company}}",
Name = "company",
TextBefore = "Company name: "
};
tx.ApplicationFields.Add(mergeField.ApplicationField);
// merge fields with MailMerge engine
using (TXTextControl.DocumentServer.MailMerge mailMerge =
new TXTextControl.DocumentServer.MailMerge())
{
mailMerge.TextComponent = tx;
mailMerge.MergeJsonData("[{\"company\": \"Text Control, LLC\" }]");
}
byte[] baPdf;
tx.Save(out baPdf, TXTextControl.BinaryStreamType.AdobePDF);
ViewBag.Document = baPdf;
}
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment