Created
February 9, 2023 15:16
-
-
Save bjoerntx/3d31be4f8234d4fb39993373f224dc2f 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
public static class Invoice { | |
public static byte[] Create(Order order) { | |
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings(); | |
var metaData = System.IO.File.ReadAllText("metadata.xml"); | |
// create a new embedded file | |
var zugferdInvoice = new TXTextControl.EmbeddedFile( | |
"ZUGFeRD-invoice.xml", | |
order.ZugferdXML, | |
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[] { zugferdInvoice }; | |
byte[] document; | |
using (TXTextControl.ServerTextControl tx = new ServerTextControl()) { | |
tx.Create(); | |
tx.Load("template.tx", StreamType.InternalUnicodeFormat); | |
using (MailMerge mailMerge = new MailMerge()) { | |
mailMerge.TextComponent = tx; | |
mailMerge.MergeObject(order); | |
} | |
// export the PDF | |
tx.Save(out document, TXTextControl.BinaryStreamType.AdobePDFA, saveSettings); | |
return document; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment