Created
March 25, 2024 16:11
-
-
Save bjoerntx/273a4222e0deeeda39b36ab4e6cd02f2 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
[HttpGet] | |
[Route("Prepare")] | |
public DocumentData Prepare() | |
{ | |
// create a new CustomerData object and serialize it to JSON | |
var customer = new CustomerData { | |
Name = "Smith", | |
FirstName = "John", | |
Street = "Main Street 1", | |
City = "New York", | |
Zip = "10001", | |
Country = "United States" | |
}; | |
var customerJson = JsonSerializer.Serialize(customer); | |
byte[] documentBytes; | |
using (var tx = new ServerTextControl()) { | |
tx.Create(); | |
tx.Load("App_Data/template.tx", StreamType.InternalUnicodeFormat); | |
// create a new MailMerge object and merge the JSON data | |
var merge = new MailMerge { | |
TextComponent = tx, | |
FormFieldMergeType = FormFieldMergeType.Preselect, | |
RemoveEmptyFields = false, | |
RemoveEmptyImages = false | |
}; | |
merge.MergeJsonData(customerJson); | |
// save the document | |
tx.Save(out documentBytes, BinaryStreamType.InternalUnicodeFormat); | |
} | |
var documentBase64 = Convert.ToBase64String(documentBytes); | |
return new DocumentData { Name = "template.pdf", Document = documentBase64 }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment