Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created September 23, 2024 13:13
Show Gist options
  • Save bjoerntx/b613de3bb721fdfcc1cf3cb118304831 to your computer and use it in GitHub Desktop.
Save bjoerntx/b613de3bb721fdfcc1cf3cb118304831 to your computer and use it in GitHub Desktop.
using System.Data;
using System.Text;
using TXTextControl.DocumentServer;
string xmlData = File.ReadAllText("data.xml");
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
tx.Load("zugferd_template.tx", TXTextControl.StreamType.InternalUnicodeFormat);
MailMerge mailMerge = new MailMerge();
mailMerge.TextComponent = tx;
// dataset from XML
DataSet ds = new DataSet();
ds.ReadXml(new MemoryStream(Encoding.UTF8.GetBytes(xmlData)));
// merge data
mailMerge.Merge(ds.Tables["SupplyChainTradeTransaction"]);
// save as PDF
tx.Save("output.pdf", TXTextControl.StreamType.AdobePDF);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment