aeat.adapters.inbound.sanitizer._metadata module

DocInfo + XMP scrub for adapters.inbound.sanitizer.

Two surfaces, two scrubbers:

  • scrub_docinfo() deletes the legacy DocInfo dictionary (Title, Subject, Author, Keywords, Creator, Producer, CreationDate, ModDate, plus any custom keys). DocInfo is the original PDF metadata format; AEAT justificantes still write to it on every render, often with the CSV embedded in the Title and Subject strings.

  • scrub_xmp() deletes the XMP packet (Root.Metadata) wholesale by default. Per-key deletion leaves orphan namespace declarations (pikepdf/pikepdf#89); the rewrite strategy is available for callers that must keep a minimal XMP packet, but the default is to drop it.

Both scrubbers also clear the PDF/A conformance claim — rewriting Tj operands invalidates PDF/A-1B’s content/XMP alignment, so leaving the claim intact would be dishonest.

scrub_docinfo(pdf)[source]

Drops the entire DocInfo dictionary from pdf.

Parameters:

pdf (Pdf) – An open pikepdf.Pdf instance whose DocInfo should be wiped. Modifies pdf in place.

Return type:

ScrubbedSurface

Returns:

A ScrubbedSurface carrying the count of DocInfo keys that were present before the wipe (zero when the document had no DocInfo dictionary).

scrub_xmp(pdf, *, strategy='delete')[source]

Drops or rewrites the XMP metadata packet on pdf.

Parameters:
  • pdf (Pdf) – An open pikepdf.Pdf instance whose XMP packet should be scrubbed. Modifies pdf in place.

  • strategy (Literal['delete', 'rewrite']) – "delete" (default) wipes Root.Metadata wholesale; "rewrite" clears every PII-bearing entry while keeping the packet intact (useful when a downstream consumer still asserts the packet exists).

Return type:

tuple[ScrubbedSurface, tuple[SanitizationWarning, ...]]

Returns:

A 2-tuple of (counter, warnings). The counter is a ScrubbedSurface recording how many top-level XMP entries were affected; the warning tuple contains SanitizationWarning entries, including pdfa_claim_invalidated when the original packet declared PDF/A conformance.