zugferd
Create, read, and validate European electronic invoices in PHP
Repository Health
Technical Analysis
horstoeko/zugferd is a PHP library for creating and reading European electronic invoices in the ZUGFeRD, XRechnung, and Factur-X standards. It lets you build compliant hybrid PDF/A-3 invoices with embedded EN 16931 XML, parse existing electronic invoices back into structured data, and validate documents against the relevant schemas and business rules.
Covering the full range of ZUGFeRD profiles from MINIMUM to EN 16931 and EXTENDED, the library abstracts the complex Cross-Industry Invoice XML behind an expressive builder and reader API, making it practical for German and wider EU e-invoicing compliance.
What You Get
- A fluent ZugferdDocumentBuilder for assembling compliant invoice documents
- Readers that parse ZUGFeRD/Factur-X XML and hybrid PDFs back into structured data
- PDF/A-3 generation that embeds the invoice XML into a human-readable PDF
- Schema (XSD) and KOSIT-based validation across all supported invoice profiles
Common Use Cases
- Generating legally compliant e-invoices for German and EU B2B and B2G transactions
- Reading and extracting structured data from incoming electronic invoices
- Validating invoice documents against EN 16931 and XRechnung business rules
Under The Hood
Architecture - The domain is modeled as JMS-serializer entities generated from the official XSD schemas (src/entities, src/schema). ZugferdDocumentBuilder exposes a fluent API that populates these entities and serializes them to Cross-Industry Invoice XML via jms/serializer; ZugferdDocumentReader reverses the process. PDF handling layers on top through ZugferdDocumentPdfBuilder, which uses FPDF/FPDI to produce PDF/A-3 files with the XML embedded, while ZugferdKositValidator shells out to the KOSIT validator for XRechnung conformance. Profiles and specification versions are resolved through ZugferdProfileResolver and ZugferdProfiles.
Tech Stack - PHP 7.3+ with the dom, libxml, simplexml, zip, and fileinfo extensions, built on jms/serializer, symfony components (validator, finder, process, yaml), setasign/fpdf and fpdi for PDF output, and smalot/pdfparser for reading. The large XSLT footprint holds the schema and validation stylesheets.
Code Quality - The project is actively maintained with frequent releases and a broad dev toolchain (PHPUnit with 50+ test files, PHPStan, PHPMD, phpcpd, pdepend, rector). Much of the entity layer is generated from schemas, keeping it consistent with the standards, and CI enforces builds on every change.
API Design - The builder/reader pairing gives an approachable entry point, but the domain itself is inherently complex: EN 16931 defines a large number of fields and constraints, so real-world use requires familiarity with the invoicing standards. Extensive examples and quick-builder helpers in src/quick ease onboarding, though the learning curve reflects the domain rather than the API.
Used by 2 apps in this directory
Invoice Ninja
Invoicing Finance · Project Management
Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.