Skip to content

Support PDF/A extension schemas and Factur-X / ZUGFeRD XMP metadata - #1808

Merged
andreasrosdalw merged 1 commit into
LibrePDF:masterfrom
andreasrosdal:pdfa3-xmp-extension-schemas
Dec 2, 2026
Merged

andreasrosdalw merged 1 commit into
LibrePDF:masterfrom
andreasrosdal:pdfa3-xmp-extension-schemas

Conversation

@andreasrosdal

@andreasrosdal andreasrosdal commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Description of the new Feature/Bugfix

OpenPDF already writes pdfaid:part=3 for PDFA3A/B/U. What was missing for real PDF/A-3 documents is custom XMP metadata with a PDF/A extension schema. PDF/A (ISO 19005-2/-3 §6.6.2.3) allows XMP properties of a namespace that is not predefined only if the metadata also describes that namespace in pdfaExtension:schemas. Otherwise veraPDF rejects the file.

The main use case is ZUGFeRD / Factur-X electronic invoices. They are PDF/A-3 documents with the invoice XML as an associated file (#1806) and with the fx: properties DocumentFileName, DocumentType, Version and ConformanceLevel in the XMP metadata.

API

writer.setPDFXConformance(PdfWriter.PDFA3B);
...
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, null, FacturXSchema.FACTUR_X_FILE_NAME,
        xml, "text/xml", params, PdfStream.BEST_COMPRESSION);
fs.setAFRelationship(PdfName.ALTERNATIVE);
writer.addAssociatedFile("Factur-X invoice", fs);                 // from #1806

FacturXSchema fx = new FacturXSchema();
fx.setDocumentFileName(FacturXSchema.FACTUR_X_FILE_NAME);
fx.setConformanceLevel(FacturXSchema.EN_16931);
writer.addXmpSchema(fx, fx.getPdfAExtensionSchema());            // new
writer.createXmpMetadata();
  • PdfAExtensionSchema (an XmpSchema) writes the extension schema container. The Schema and Property records describe a namespace and its properties, and a namespace is described only once.
  • FacturXSchema has the fx: properties (INVOICE and version 1.0 by default), constants for the profiles (MINIMUM … XRECHNUNG) and file names, and getPdfAExtensionSchema(). It supports the Factur-X / ZUGFeRD 2.1+ namespace and, with a constructor argument, the ZUGFeRD 2.0 namespace.
  • PdfWriter.addXmpSchema(XmpSchema) and addXmpSchema(XmpSchema, PdfAExtensionSchema.Schema) add schemas to the metadata that createXmpMetadata() generates. Before, custom properties meant writing the whole XMP packet by hand with setXmpMetadata(byte[]).

All of this is new API. Documents that do not call addXmpSchema do not change.

Unit-Tests for the new Feature/Bugfix

New PdfAExtensionSchemaTest:

  • The extension schema XML has the namespace declarations and the schema and property elements, with XML escaping.
  • A namespace that is added twice is described once.
  • FacturXSchema defaults, setters and the ZUGFeRD 2.0 namespace.
  • A Factur-X style PDF/A-3b invoice validated with veraPDF: embedded font, sRGB output intent, factur-x.xml as an associated file with /AFRelationship /Alternative, the MIME type and /ModDate, and the fx: properties with their extension schema. veraPDF reports no violations.

./mvnw -B install passes locally on Java 25 for all modules, and checkstyle:check reports nothing on the new files. The changelog for 4.0.1 is updated.

Not in this PR: generating or checking the invoice XML itself (CII/UBL), which is outside the scope of a PDF library.

@codacy-production

codacy-production Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 35 complexity · 1 duplication

Metric Results
Complexity 35
Duplication 1

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

PDF/A allows XMP properties of a namespace that is not predefined only
if the metadata describes the namespace in an extension schema
(pdfaExtension:schemas). ZUGFeRD and Factur-X invoices are PDF/A-3
documents with such properties (fx:DocumentFileName, DocumentType,
Version and ConformanceLevel).

- PdfAExtensionSchema writes the extension schema container, with
  records for the schema and property descriptions.
- FacturXSchema has the fx properties and their extension schema, for
  Factur-X and ZUGFeRD 2.1 and later, and for ZUGFeRD 2.0.
- PdfWriter.addXmpSchema(XmpSchema) and addXmpSchema(XmpSchema,
  PdfAExtensionSchema.Schema) add schemas to the metadata that
  createXmpMetadata() creates.

A Factur-X style PDF/A-3b invoice, with the invoice XML as an
associated file, passes veraPDF.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@andreasrosdal
andreasrosdal force-pushed the pdfa3-xmp-extension-schemas branch from fc46476 to f7f411a Compare December 2, 2026 21:39
@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

@andreasrosdalw
andreasrosdalw merged commit d531ac4 into LibrePDF:master Dec 2, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants