Table of Contents

Class FacturX

Namespace
MiPdf.Invoicing
Assembly
MiPdf.dll

Hybrid e-invoices according to Factur-X 1.0 / ZUGFeRD 2.x: a PDF/A-3 document with the structured invoice (UN/CEFACT Cross Industry Invoice XML) as associated file and the Factur-X XMP metadata.

public static class FacturX
Inheritance
FacturX
Inherited Members

Examples

using var pdf = PdfDocument.Create();
// ... render the human-readable invoice with embedded fonts ...
FacturX.Attach(pdf, File.ReadAllBytes("factur-x.xml"), FacturXProfile.EN16931);
pdf.Save("invoice.pdf");    // PDF/A-3b with factur-x.xml

Fields

NamespaceUri

XMP namespace of the Factur-X extension schema.

public const string NamespaceUri = "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#"

Field Value

string

Methods

Attach(PdfDocument, byte[], FacturXProfile, string?)

Embeds the invoice XML and prepares the document for PDF/A-3 (sets Conformance to PDF/A-3b unless a PDF/A-3 level is already set). Fonts must be embedded for a valid PDF/A document.

public static PdfAttachment Attach(PdfDocument document, byte[] xml, FacturXProfile profile, string? fileName = null)

Parameters

document PdfDocument

The visual invoice.

xml byte[]

The CII invoice XML (UTF-8).

profile FacturXProfile

Profile of the XML.

fileName string

Attachment name (default "factur-x.xml", or "xrechnung.xml" for XRechnung).

Returns

PdfAttachment

Exceptions

ArgumentException

The XML is not well-formed, or its guideline ID (BT-24) names a different profile.

CheckConsistency(PdfDocument)

Checks whether the key values of the embedded invoice XML appear in the visible text of the PDF: invoice number (BT-1), issue date (BT-2), seller and buyer name (BT-27, BT-44), seller VAT identifier (BT-31), IBAN (BT-84) and the totals (BT-109, BT-110, BT-112, BT-115). Returns the values that were not found; an empty list means the visible invoice is consistent with the XML as far as this check can tell.

public static IReadOnlyList<FacturXFinding> CheckConsistency(PdfDocument document)

Parameters

document PdfDocument

Returns

IReadOnlyList<FacturXFinding>

Remarks

This is a plausibility check, not a validation: a PDF has no semantic structure, so a value counts as found if it appears anywhere in the text. Common formats are recognised – grouped IBANs and VAT identifiers, amounts with two decimals in German, English and Swiss notation, numeric dates and German, English and French month names. For incoming invoices the XML is legally binding; a value that differs in the PDF (for example another IBAN) is a reason to look closer. Scanned invoices without a text layer report every value.

Exceptions

PdfException

The document contains no Factur-X/ZUGFeRD invoice, or its XML is not well-formed.

ConformanceLevel(FacturXProfile)

The value of fx:ConformanceLevel for a profile.

public static string ConformanceLevel(FacturXProfile profile)

Parameters

profile FacturXProfile

Returns

string

DetectProfile(byte[])

Determines the profile from the guideline ID (BT-24) of a CII invoice, for example urn:cen.eu:en16931:2017 → EN16931. Returns null if the ID is missing or unknown.

public static FacturXProfile? DetectProfile(byte[] xml)

Parameters

xml byte[]

Returns

FacturXProfile?

Exceptions

ArgumentException

The XML is not well-formed.

GetInvoiceXml(PdfDocument)

Returns the embedded invoice XML of a Factur-X/ZUGFeRD document, or null.

public static byte[]? GetInvoiceXml(PdfDocument document)

Parameters

document PdfDocument

Returns

byte[]

GetProfile(PdfDocument)

Returns the profile declared in the XMP metadata (fx:ConformanceLevel), or null.

public static FacturXProfile? GetProfile(PdfDocument document)

Parameters

document PdfDocument

Returns

FacturXProfile?