Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created September 30, 2024 14:37
Show Gist options
  • Save bjoerntx/12ac7bbc11dcd0444ff3c43741dbe49a to your computer and use it in GitHub Desktop.
Save bjoerntx/12ac7bbc11dcd0444ff3c43741dbe49a to your computer and use it in GitHub Desktop.
using TXTextControl;
using TXTextControl.DocumentServer;
using TXTextControl.DocumentServer.DataSources;
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
string jsonData = File.ReadAllText("tabledata.json");
DataSourceManager dataSourceManager = new DataSourceManager();
dataSourceManager.LoadJson(jsonData);
MergeBlockInfo mergeBlockInfo = new MergeBlockInfo("items");
mergeBlockInfo.ColumnNames.Add("product");
mergeBlockInfo.ColumnNames.Add("price");
mergeBlockInfo.ColumnNames.Add("quantity");
MergeBlockSettings mergeBlockSettings = new MergeBlockSettings(BlockTemplateType.TableRow, true);
dataSourceManager.InsertMergeBlock(tx, mergeBlockInfo, mergeBlockSettings);
MailMerge mailMerge = new MailMerge()
{
TextComponent = tx
};
mailMerge.MergeJsonData(jsonData);
// save the document as PDF
tx.Save("results.pdf", StreamType.AdobePDF);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment