1. Go to this page and download the library: Download pat-o-dev/factur-x library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pat-o-dev / factur-x example snippets
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[]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.