From d1604b038875dc0ccd1012b4b7b1453a3c222594 Mon Sep 17 00:00:00 2001 From: dfuhrmann3 Date: Fri, 3 Jul 2026 13:25:51 +0200 Subject: [PATCH] ZUGFeRD fix 3 --- main.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index e7ea1a7..f822153 100644 --- a/main.py +++ b/main.py @@ -583,15 +583,72 @@ with col2: ) else: try: - # 🔥 FIX: mime-Parameter entfernt, da von PyMuPDF nicht unterstützt original_pdf_bytes = uploaded_file.getvalue() doc = fitz.open(stream=original_pdf_bytes, filetype="pdf") + + # 🔥 OPTIMIERUNG 1: Setze das zwingend erforderliche PDF/A-3 Beziehungs-Flag 'Alternative' doc.embfile_add( "factur-x.xml", xml_string.encode("utf-8"), filename="factur-x.xml", - desc="Factur-X/ZUGFeRD E-Invoice" + desc="Factur-X/ZUGFeRD E-Invoice", + relationship="Alternative" ) + + # 🔥 OPTIMIERUNG 2: Injiziere das offizielle Factur-X / ZUGFeRD 2.x XMP-Schema in den PDF-Header + xmp_xml = """ + + + + + + + Factur-X PDFA Extension Schema + fx + urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0# + + + + DocumentType + Text + external + The type of the document, usually INVOICE + + + DocumentFileName + Text + external + The name of the embedded file + + + Version + Text + external + The version of the document type schema + + + ConformanceLevel + Text + external + The conformance level of the document + + + + + + + + + INVOICE + factur-x.xml + 1.0 + XRECHNUNG + + + +""" + + doc.set_xmp_metadata(xmp_xml) zugferd_pdf_bytes = doc.tobytes() doc.close()