NAME

PDF::FacturX - Generate Factur-X / ZUGFeRD-compatible PDF/A-3 invoices

SYNOPSIS

use PDF::FacturX qw(generate);

my ($ok, $msg) = generate(
    pdf_in  => 'invoice-source.pdf',   # any visual PDF
    pdf_out => 'invoice-facturx.pdf',  # PDF/A-3 with XML attached
    invoice => {
        number   => 'FA-2026-0042',
        date     => '2026-04-19',
        due_date => '2026-05-19',
        currency => 'EUR',
        seller   => {
            name      => 'Acme SARL',
            siret     => '12345678901234',
            vat       => 'FR12345678901',
            address_1 => '1 rue de la Paix',
            postcode  => '75001',
            city      => 'Paris',
            country   => 'FR',
        },
        buyer => {
            name      => 'Kunde GmbH',
            address_1 => 'Hauptstrasse 1',
            postcode  => '10115',
            city      => 'Berlin',
            country   => 'DE',
        },
        lines => [
            { name => 'Consulting', qty => 8, unit_price => 125,
              vat_rate => 20, vat_cat => 'S' },
        ],
        payment => {
            terms => 'Net 30',
            iban  => 'FR7612345678901234567890123',
            bic   => 'BNPAFRPP',
        },
    },
    profile => 'en16931',
    title   => 'Facture FA-2026-0042',
    author  => 'Acme SARL',
);
die "Factur-X generation failed: $msg" unless $ok;

DESCRIPTION

PDF::FacturX generates compliant Factur-X / ZUGFeRD invoices: a PDF/A-3 file embedding the structured CrossIndustryInvoice XML defined by the European Norm EN 16931. Factur-X is the joint Franco-German specification published by FNFE-MPE (France) and FeRD (Germany) and is the reference format for the French B2B e-invoicing reform (mandatory rollout 2026-2027) and the German ZUGFeRD ecosystem.

The module orchestrates two lower-level modules:

  • PDF::FacturX::XML — builds and validates the XML against the official XSD bundled with this distribution.

  • PDF::FacturX::Embed — wraps an existing PDF into a PDF/A-3 envelope with the XML attached as an associated file (AFRelationship = /Data) and the XMP metadata stream required by PDF/A-3.

SUPPORTED PROFILES

  • minimum — header data only

  • basicwl — without lines

  • basic — line items + tax breakdown (compliant EN 16931)

  • en16931 — full European Norm

FUNCTIONS

generate(%opts)

Returns (1, $info) on success or (0, $error_message) on failure.

Required options:

pdf_in — path to the source PDF
pdf_out — path to write the resulting PDF/A-3
invoice — invoice hash (see PDF::FacturX::XML)

Optional options:

profile — one of minimum|basicwl|basic|en16931 (default basic)
validate — 1 to validate XML against XSD before embedding (default 1)
title, author, creator — PDF metadata
tmp_dir — directory for ephemeral files (default: system temp)
gs — Ghostscript binary (default gs)
icc_path — path to sRGB ICC profile (default: auto-detect)
on_warning — coderef called with PDF::Builder warnings

REQUIREMENTS

SEE ALSO

LICENSE

This software is copyright (c) 2026 by huguesmax.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself: the Artistic License 2.0.