Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created January 2, 2025 12:21
Show Gist options
  • Select an option

  • Save bjoerntx/4c57ffd78ce4cf242522dced9fdf1def to your computer and use it in GitHub Desktop.

Select an option

Save bjoerntx/4c57ffd78ce4cf242522dced9fdf1def to your computer and use it in GitHub Desktop.
// Serialize the XRechnung object to JSON
string json = JsonSerializer.Serialize(xRechnung);
// Generate the ZUGFeRD XML
string xmlZugferd = xRechnung.CreateXML();
// Load metadata from the XML file
string metaData = File.ReadAllText("metadata.xml");
// Create an embedded file for the ZUGFeRD invoice
var zugferdInvoice = new TXTextControl.EmbeddedFile(
"factur-x.xml",
Encoding.UTF8.GetBytes(xmlZugferd),
metaData)
{
Description = "factur-x",
Relationship = "Alternative",
MIMEType = "application/xml",
LastModificationDate = DateTime.Now
};
// Configure save settings with the embedded file
var saveSettings = new TXTextControl.SaveSettings
{
EmbeddedFiles = new[] { zugferdInvoice }
};
// Create, modify, and save the PDF document
using (var tx = new TXTextControl.ServerTextControl())
{
tx.Create();
tx.Text = "Test Document";
tx.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