Last active
April 28, 2020 07:23
-
-
Save bjoerntx/48e02e7b3b384e7a0876a4a64559e9f8 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
[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