The Word to PDF Converter creates electronic invoices in the Factur-X and ZUGFeRD formats (including the XRechnung profile) and electronic orders in the Order-X format from a Word document. An electronic invoice is a PDF/A-3 document that shows the invoice as a page a person reads and carries the same invoice as an XML file that accounting software reads automatically. The Word document gives the visible page and the invoice XML is embedded as given.
The invoice XML is loaded in an EvoPdf.NextElectronicInvoice object with ElectronicInvoiceFromXml(Byte), ElectronicInvoiceFromXml(String) or ElectronicInvoiceFromFile(String) and added to the generated document with WordToPdfDocumentOptionsAddElectronicInvoice(ElectronicInvoice). The profile, the document type and the invoice number are taken from the XML. The supported profiles and document types are listed in the Create Factur-X, ZUGFeRD and XRechnung Electronic Invoices documentation section. The Excel, RTF and Markdown to PDF converters embed an electronic invoice the same way.
The document must be a PDF/A-3 document: WordToPdfDocumentOptionsPdfStandard must be set to PdfStandardPdfA3b, PdfStandardPdfA3u, PdfStandardPdfA3a or PdfStandardPdfUa1PdfA3a. With the last one the invoice page is also an accessible PDF/UA-1 document, with a structure that follows the headings, paragraphs, tables and images of the Word document
The Relationship property describes how the XML relates to the visible page. The default is Alternative, meaning the XML and the page carry the same invoice. The MINIMUM and BASIC WL profiles do not carry the complete invoice, so for them the relationship is always Data
One electronic invoice can be added to a document
Setting WordToPdfConverterPdfViewerPreferences.PageMode to ViewerPageModeUseAttachments opens the Attachments panel when the document is loaded, so the embedded invoice XML is visible to the reader.
// Use EVO PDF Namespace
using EvoPdf.Next;
public byte[] CreateElectronicInvoiceFromWord(byte[] inputWordBytes, byte[] invoiceXml)
{
// Set the license key received after purchase to use the library in licensed mode; leave it commented for demo mode
// Licensing.LicenseKey = "your-license-key";
// Read the invoice. The profile and the document type (invoice, credit note, order...) are
// taken from the XML itself
ElectronicInvoice invoice = ElectronicInvoice.FromXml(invoiceXml);
// How the embedded XML relates to the visible page. MINIMUM and BASIC WL do not carry
// the whole invoice, so for them the relationship is always Data
invoice.Relationship = PdfAttachmentRelationship.Alternative;
// Create a Word to PDF converter object with default settings
WordToPdfConverter wordToPdfConverter = new WordToPdfConverter();
// An electronic invoice needs a PDF/A-3 carrier. PDF/UA-1 + PDF/A-3a produces an
// invoice that is also accessible
wordToPdfConverter.PdfDocumentOptions.PdfStandard = PdfStandard.PdfUa1PdfA3a;
// Embed the invoice XML and write the metadata invoice software looks for. The Excel,
// RTF and Markdown to PDF converters embed an electronic invoice the same way
wordToPdfConverter.PdfDocumentOptions.AddElectronicInvoice(invoice);
// Open the Attachments panel on document load, so the embedded XML is visible
wordToPdfConverter.PdfViewerPreferences.PageMode = ViewerPageMode.UseAttachments;
// The buffer to receive the generated PDF document
byte[] outPdfBuffer = wordToPdfConverter.ConvertToPdf(inputWordBytes);
return outPdfBuffer;
}