Skip to content

Repository files navigation

Factur-X and Order-X JS library

Generate, extract, parse and validate Factur-X / ZUGFeRD and Order-X e-invoices in TypeScript, using pdf-lib and libxml2-wasm.

Conforms to Factur-X 1.09 / ZUGFeRD 2.5 (the EN 16931 European e-invoicing standard, CII D22B).

📖 Read the full documentation →

Features

  • 📎 Generate a PDF-A/3 invoice by embedding the XML into a PDF — generate
  • 📤 Extract the XML back out of a Factur-X / Order-X / ZUGFeRD PDF — extract
  • 🔁 Parse an XML invoice into a fully-typed model — xmlToInvoice
  • 🧱 Build a Cross Industry Invoice model and serialize it to XML — invoiceToXml
  • Validate against the official 1.09 XSD, and optionally the Schematron EN 16931 BR-* business rules and code lists — check (schematron: true) / validateSchematron
  • 🗂 All five Factur-X profiles: minimum, basicwl, basic, en16931, extended

See Profiles & flavors for the supported flavors, levels and autodetection rules.

Install

npm install @stafyniaksacha/facturx

Requires Node.js ≥ 20.11.0. The package is ESM-only and ships its own types.

Quick start

# CLI — no install required
npx @stafyniaksacha/facturx extract invoice.pdf > factur-x.xml
npx @stafyniaksacha/facturx check factur-x.xml --schematron
import { check, extract, generate } from '@stafyniaksacha/facturx'

// Embed an XML invoice into a PDF → compliant PDF/A-3 bytes
const facturxPdf = await generate({ pdf, xml })

// Pull the embedded XML back out of a Factur-X / Order-X / ZUGFeRD PDF
const { xml: extractedXml, flavor, level } = await extract({ pdf })

// Validate against the XSD (and, with schematron: true, the EN 16931 business rules)
const { valid, errors } = await check({ xml })

The flavor and level are autodetected from the XML when not provided.

Documentation

Full guides and the complete API reference live on the docs site:

Useful links

License

Based on original work of akretion/factur-x python library by Alexis de Lattre

About

Generate and extract Factur-X and Order-X invoices

Topics

Resources

Stars

23 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages