Created
July 10, 2020 14:26
-
-
Save bjoerntx/1d672032ec083f54018fd361db6532a7 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) }; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment