Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created July 10, 2020 14:26
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/1d672032ec083f54018fd361db6532a7 to your computer and use it in GitHub Desktop.
Save bjoerntx/1d672032ec083f54018fd361db6532a7 to your computer and use it in GitHub Desktop.
[ApiController]
[Route("[controller]")]
public class TextControlController : ControllerBase
{
[HttpPost]
[Route("MergeDocument")]
public MergedDocument MergeDocument([FromBody] MergedDocument Document)
{
byte[] data;
// create dummy merge data
Customer customer = new Customer() { Firstname = "Klaus", Name = "Klaasen" };
// new ServerTextControl instance
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
// load the document from the payload
tx.Load(Convert.FromBase64String(Document.Document),
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
TXTextControl.DocumentServer.MailMerge mm =
new TXTextControl.DocumentServer.MailMerge();
mm.TextComponent = tx;
mm.MergeObject(customer); // merge the data into template
// save document into byte array
tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// return the document to the client
return new MergedDocument() { Document = Convert.ToBase64String(data) };
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment