Created
May 6, 2020 14:02
-
-
Save bjoerntx/6332487c4c99af15126351652946e889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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) }; | |
} | |
} | |
[HttpGet] | |
[Route("LoadData")] | |
public Customer[] LoadData() | |
{ | |
// return dummy excerpt data | |
return new Customer[] { new Customer() { Firstname = "Klaus", Name = "Klaasen" } }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment