Factur-X invoice

A French invoice with its EN 16931 XML in one PDF

Download template

Sample data

Template
DOCX
Export as
PDF, DOCX, ODT, HTML, PNG +25 more
Carbone
5.18+

Generate Factur-X invoices from your invoicing software

Factur-X, known as ZUGFeRD in Germany, is a PDF that people can read, with an XML file embedded inside that accounting software can process automatically. Your invoicing software or ERP sends the invoice data to the Carbone API, which generates the PDF from your template, builds the XML from the same data, and attaches it to the PDF in the same request.

In France, the e-invoicing reform keeps the existing mandatory mentions of an invoice and adds four: the SIREN of the customer, the category of the operation (goods, services or both), the option to pay VAT on debits when it applies, and the delivery address when it differs from the billing address. According to impots.gouv.fr, they are mandatory from September 1, 2026. This example shows all of them, and embeds the EN 16931 profile, which carries the full invoice: parties, lines, VAT breakdown and payment terms.

   1- Template
  ┌─────────────────┐
  │   *.docx        │       ┌─────────┐
  │                 ┼───┐   │         │
  │ :attachFile     │   │   │         │
  │ ('factur-x.xml')│   └───►         │     Export
  └─────────────────┘       │ Carbone │    ┌───────┐
                            │         │    │ *.pdf │
             2- Data    ┌───►         ┼────►     ┌─┴┐
            ┌───────┐   │   │         │    │     │┌┐│
            │*.json ┼───┘   │         │    └─────┤│││
            └───────┘     ┌─►         │          │ │
                          │ │         │          └─┘*.xml
             3- XML       │ │         │
            ┌───────┐     │ └─────────┘
            │*.xml  ┼─────┘
            └───────┘

In this example, you will:

  • Print the French mandatory mentions: SIREN and VAT number of both companies, dates, late payment penalties and the 40 EUR recovery fee
  • Calculate the totals from the invoice lines, once for the PDF and once for the XML
  • Generate the EN 16931 XML from an XML template and the same JSON data
  • Attach the XML file to the generated PDF

How to embed the EN 16931 XML in a PDF invoice

1. Design the Invoice Layout

  • Design the invoice with tables for the dates, the parties, the lines, the totals and the payment details. You can get inspiration from the utility invoice example.
  • Insert Carbone tags wherever your data should appear, for example {d.invoice.number} for the invoice number and {d.invoice.issueDate:formatD(DD/MM/YYYY)} for the issue date.
  • Print the reform mentions from your data: {d.invoice.buyer.siren} for the customer SIREN, {d.invoice.operationNature} for the nature of the operation, and a block for {d.invoice.delivery.address.street} when the goods go to another address.
  • Print the payment conditions: {d.invoice.latePenaltyRate:formatN(0)} for the penalty rate and {d.invoice.recoveryFee:formatC()} for the fixed recovery fee.
  • List the lines with a loop on {d.invoice.lines[i].description}, and close it on the next row with {d.invoice.lines[i+1].description}.

2. Calculate the Totals

Calculate the net total with :aggSum, and store it in the complement object c to reuse it in several places:

{d.invoice.lines[].price:mul(.quantity):round(2):aggSum:set(c.net)}

Then print it with {c.net:formatC()}. Calculate the VAT with {c.net:mul(d.invoice.vatRate):div(100):round(2):set(c.vat)}, and the total with {c.net:add(c.vat):round(2):formatC()}.

Tip: long tags can wrap anywhere in a narrow cell. Add a space where you want the line to break, for example {d.invoice.lines[].price :mul(.quantity) :round(2) :aggSum :set(c.net)}. Carbone ignores these spaces when generating the document.

3. Generate the XML File

The Factur-X XML file describes the invoice in a structured format: seller, buyer, delivery, dates, lines, VAT and amounts. Write it as an XML template in the EN 16931 profile (urn:cen.eu:en16931:2017), with the same tags and the same totals as the PDF:

<ram:BuyerTradeParty>
  <ram:Name>{d.invoice.buyer.name}</ram:Name>
  <ram:SpecifiedLegalOrganization>
    <ram:ID schemeID="0002">{d.invoice.buyer.siren}</ram:ID>
  </ram:SpecifiedLegalOrganization>
</ram:BuyerTradeParty>

Render this template with your JSON data, then add the result to the same data, either as a URL or as a Base64 data URI:

{
  "xmlUrl": "data:text/xml;base64,PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0n...",
  "invoice": { ... }
}

Make sure that the amounts of the XML match the totals displayed in the PDF. In this example, the XML was also checked with the official EN 16931 CII validation rules.

4. Attach the XML File to the PDF

Anywhere in the template, insert this tag. It prints nothing:

{d.xmlUrl:attachFile(factur-x.xml)}

The :attachFile formatter downloads the file and attaches it to the generated PDF under the name factur-x.xml. With this name, Carbone generates a Factur-X PDF:

  • It detects the profile from the XML file (MINIMUM, BASIC WL, BASIC, EN 16931 or EXTENDED) and adds the matching PDF metadata.
  • It exports the document as PDF/A-3B, unless you choose another PDF version in the converter options.

The second parameter of :attachFile sets the relationship of the file with the PDF: Data by default, or Source, Alternative, Supplement, Unspecified, FormData and Schema.

Save the DOCX template, connect it to your JSON data, and let Carbone generate a French PDF invoice with its Factur-X XML file automatically.

Check out these similar templates to learn more:

Trusted by 800+ paid customers in 40+ countries

Finance
Healthcare
Insurance
Legal
Public
Retail
Energy
Software
Telecom
Dior
Thales
Younited
Danfoss
CMA CGM
Illumina
KparK
Scalingo
French Ministry of the Armed Forces
BMW
Telus
Bestseller
Flagship Biosciences
Insly
Ninox
Sodexo