PHPackages                             pat-o-dev/factur-x - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pat-o-dev/factur-x

ActiveLibrary

pat-o-dev/factur-x
==================

Framework-agnostic PHP generator for Factur-X invoices (French e-invoicing reform, XP Z12-012 / EN 16931), producing CII D22B XML and hybrid PDF/A-3.

v0.3.0(today)127↑2788.9%1MITPHPPHP ^8.2

Since Jul 30Pushed todayCompare

[ Source](https://github.com/pat-o-dev/factur-x)[ Packagist](https://packagist.org/packages/pat-o-dev/factur-x)[ RSS](/packages/pat-o-dev-factur-x/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (6)Used By (1)

pat-o-dev/factur-x
==================

[](#pat-o-devfactur-x)

Framework-agnostic PHP library to generate **Factur-X** invoices for the French e-invoicing reform (norme AFNOR XP Z12-012 / EN 16931), in pure PHP with no Laravel/Symfony dependency. Pairs with [`pat-o-dev/factur-x-laravel`](../factur-x-laravel)for Laravel projects; a Symfony bundle can reuse this package the same way.

Most existing open-source Factur-X/ZUGFeRD libraries are built and documented primarily for the German ZUGFeRD use case. This package targets the **French CIUS (profil EN 16931)** described in XP Z12-012 first, with the `EXTENDED-CTC-FR` profile and the French `BR-FR-*` business rules planned for a later release.

What it does
------------

[](#what-it-does)

1. **Builds the `factur-x.xml`** payload (UN/CEFACT CII D22B syntax, EN 16931 profile) from a plain PHP `Invoice` object — header, parties, lines, allowances/charges, VAT breakdown and monetary totals.
2. **Turns an existing PDF into a Factur-X hybrid PDF** by appending, as a classic PDF *incremental update* (the same mechanism digital signatures use), the XML as an embedded file (`/AF`, `/Names /EmbeddedFiles`) plus the XMP metadata declaring the PDF/A-3 + Factur-X extension schema.

What it does NOT do (yet)
-------------------------

[](#what-it-does-not-do-yet)

- It does **not** render the human-readable PDF invoice itself, and it does **not** convert an arbitrary PDF into full PDF/A-3 conformance (ICC output intent, font embedding, colour space restrictions...). Feed it a PDF that is already PDF/A-compliant (mPDF and TCPDF both ship a PDF/A mode) — this library only adds the Factur-X-specific attachment + metadata layer.
- The PDF attacher only supports **classic (non cross-reference-stream), unencrypted PDFs** whose Catalog does not already declare `/Names` or `/AF`(an already-hybridized/attachment-bearing PDF). An existing `/Metadata`reference (which mPDF/TCPDF always emit in PDF/A mode) is reused in place rather than rejected. Anything unsupported raises `UnsupportedPdfException`rather than silently producing a broken file.
- The XML writer covers the fields most B2B invoices need (header identification, seller/buyer/delivery party, key references, notes, lines with allowances/charges, VAT breakdown, one payment mean, totals) but not the full ~160 EN 16931 business terms yet, and not the `EXTENDED-CTC-FR`data (multi-seller invoices, sub-lines, ...).

Usage
-----

[](#usage)

```
use PatODev\FacturX\Enum\InvoiceTypeCode;
use PatODev\FacturX\Enum\UnitOfMeasureCode;
use PatODev\FacturX\Enum\VatCategory;
use PatODev\FacturX\FacturXGenerator;
use PatODev\FacturX\Model\{Address, Invoice, InvoiceLine, Party};

$seller = new Party(
    name: 'ACME Transport SARL',
    address: new Address(line1: '1 rue des Tests', city: 'Paris', postalCode: '75001', countryCode: 'FR'),
    legalRegistrationId: '123456789',
    vatNumber: 'FR12123456789',
);

$buyer = new Party(
    name: 'Client SAS',
    address: new Address(line1: '2 avenue du Test', city: 'Lyon', postalCode: '69001', countryCode: 'FR'),
    legalRegistrationId: '987654321',
);

$invoice = new Invoice(
    number: 'F20260001',
    issueDate: new DateTimeImmutable('2026-01-15'),
    typeCode: InvoiceTypeCode::CommercialInvoice,
    seller: $seller,
    buyer: $buyer,
);

$invoice->addLine(new InvoiceLine(
    lineId: '1',
    itemName: 'Prestation de transport',
    quantity: 2.0,
    unitCode: UnitOfMeasureCode::Piece,
    netUnitPrice: 100.0,
    vatCategory: VatCategory::Standard,
    vatRate: 20.0,
));

$generator = new FacturXGenerator();

// Standalone XML:
$xml = $generator->generateXml($invoice);

// Hybrid PDF, given a visual PDF you already generated (e.g. via mPDF):
$hybridPdf = $generator->generateHybridPdf($invoice, $basePdfBytes);

// Reverse: pull the embedded XML back out of an existing hybrid PDF...
$extractedXml = (new \PatODev\FacturX\Pdf\EmbeddedXmlExtractor())->extract($hybridPdf);

// ...and check it against a curated set of business rules:
$report = (new \PatODev\FacturX\Validation\InvoiceValidator())->validate($extractedXml);
$report->passed(); // bool
$report->failures(); // RuleResult[]
```

Testing
-------

[](#testing)

```
composer install
vendor/bin/phpunit
```

Validating an existing invoice
------------------------------

[](#validating-an-existing-invoice)

`InvoiceValidator` checks a curated, hand-picked set of business rules — not the full official EN 16931 schematron ruleset (see Roadmap):

- Structural: well-formed XML, correct root element/namespace, at least one line, a seller and a buyer party.
- `BR-CO-15`: tax basis total + tax total = grand total, plus a sub-rule (`BR-CO-15-currencyID`) that the tax total amount carries a `currencyID`attribute (required by most EN 16931 validators, e.g. KoSIT).
- `BR-CO-25`: if the amount due is positive, a due date or payment terms text must be present.
- `BR-CO-5-6`: every allowance/charge has a reason code or reason text.

Feed it XML extracted from a hybrid PDF via `EmbeddedXmlExtractor` (classic, unencrypted PDFs only, same limitation class as `PdfA3Attacher`; both our own uncompressed streams and third-party `/FlateDecode`-compressed ones are supported) or raw `factur-x.xml` content directly.

Roadmap
-------

[](#roadmap)

- `EXTENDED-CTC-FR` profile (multi-seller/bi-directional invoices, sub-lines).
- Full `BR-FR-*` business rule validation (growing `InvoiceValidator`'s rule set).
- Schematron-based conformance testing against the official EN 16931 rules.
- Cross-reference-stream PDF support in the attacher and extractor.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance100

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f750c9ddd09ad33c73ac64d79ef94a382b0ad01c0b1a395233b568b67af6151?d=identicon)[PatODev](/maintainers/PatODev)

---

Top Contributors

[![pat-o-dev](https://avatars.githubusercontent.com/u/28396761?v=4)](https://github.com/pat-o-dev "pat-o-dev (9 commits)")

---

Tags

ZUGFeRDfactur-xciie-invoicingEN16931facture-electroniquepdf-a-3

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pat-o-dev-factur-x/health.svg)

```
[![Health](https://phpackages.com/badges/pat-o-dev-factur-x/health.svg)](https://phpackages.com/packages/pat-o-dev-factur-x)
```

###  Alternatives

[easybill/e-invoicing

A package to read and create EN16931 e-invoices or CIUS like: XRechnung, ZUGFeRD etc.

14158.3k](/packages/easybill-e-invoicing)[horstoeko/zugferd

A library for creating and reading european electronic invoices

4295.8M31](/packages/horstoeko-zugferd)[atgp/factur-x

PHP library to manage your Factur-X / ZUGFeRD 2.0 PDF invoices files

153915.3k4](/packages/atgp-factur-x)[easybill/zugferd-php

ZUGFeRD PHP SDK (Factur-X, XRechnung) - Convert PHP Objects to XML and back.

102328.4k11](/packages/easybill-zugferd-php)[horstoeko/zugferdublbridge

Convert Factur-X/ZUGFeRD (CII-Syntax) to PEPPOL (UBL-Syntax) and visa versa

16175.4k10](/packages/horstoeko-zugferdublbridge)[horstoeko/zugferd-laravel

A library for Laravel-Framework for creating and reading european electronic invoices

41138.5k2](/packages/horstoeko-zugferd-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
