Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created February 3, 2021 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/d179839d2a567ecad8b60b47fa32f081 to your computer and use it in GitHub Desktop.
Save bjoerntx/d179839d2a567ecad8b60b47fa32f081 to your computer and use it in GitHub Desktop.
TXTextControl.DocumentServer.MailMerge mm = new TXTextControl.DocumentServer.MailMerge();
mm.TextComponent = textControl1;
textControl1.Load("invoice.tx", TXTextControl.StreamType.InternalUnicodeFormat);
Invoice invoice = CreateSampleInvoice();
// merge data into template
mm.MergeJsonData(JsonConvert.SerializeObject(invoice));
// create the XML
string xmlZugferd = invoice.CreateXml();
// get the required meta data
string metaData = MetaData.GetMetaData();
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings();
// create a new embedded file
var zugferdInvoice = new TXTextControl.EmbeddedFile(
"ZUGFeRD-invoice.xml",
Encoding.UTF8.GetBytes(xmlZugferd),
metaData);
zugferdInvoice.Description = "ZUGFeRD-invoice";
zugferdInvoice.Relationship = "Alternative";
zugferdInvoice.MIMEType = "application/xml";
zugferdInvoice.LastModificationDate = DateTime.Now;
// set the embedded files
saveSettings.EmbeddedFiles = new TXTextControl.EmbeddedFile[] {
new TXTextControl.EmbeddedFile(
"ZUGFeRD-invoice.xml",
Encoding.UTF8.GetBytes(xmlZugferd),
metaData) };
// export the PDF
textControl1.Save("test.pdf", TXTextControl.StreamType.AdobePDFA, saveSettings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment