Created
December 21, 2022 13:58
-
-
Save bjoerntx/94a48659272080ad3638e87083485d43 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] | |
public string PDFPrepare(bool flatten) { | |
byte[] bDocument; | |
// create temporary ServerTextControl | |
using (ServerTextControl tx = new ServerTextControl()) { | |
tx.Create(); | |
// loading the template | |
tx.Load(Server.MapPath("~/App_Data/Documents/patient_history.tx"), StreamType.InternalUnicodeFormat); | |
// fire up the MailMerge engine | |
using (MailMerge mailMerge = new MailMerge()) { | |
mailMerge.TextComponent = tx; // connect to ServerTextControl | |
// pre-selecting form fields | |
if (flatten == false) | |
mailMerge.FormFieldMergeType = FormFieldMergeType.Preselect; | |
else // flatten form fields | |
mailMerge.FormFieldMergeType = FormFieldMergeType.Replace; | |
string jsonData = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/Documents/data.json")); | |
// merge JSON into fields | |
mailMerge.MergeJsonData(jsonData); | |
} | |
// export to PDF | |
tx.Save(out bDocument, BinaryStreamType.InternalUnicodeFormat); | |
} | |
// return as Base64 encoded string | |
return Convert.ToBase64String(bDocument); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment