IText – PDF/A – XMP-Metadaten für ZUGFeRD-Rechnung festlegen

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: IText – PDF/A – XMP-Metadaten für ZUGFeRD-Rechnung festlegen

by Guest » 21 Dec 2024, 12:54

Ich habe ein Problem mit der Verarbeitung von XMP-Metadaten beim Generieren einer ZUGFeRD-Rechnung in PDF/A 3b. Zunächst muss ich sagen, dass ich noch nie mit XMP-Metadaten in Berührung gekommen bin, daher ist das wirklich ein sehr neues Thema für mich.
Ich verwende Version 8.0.5 des iText-Pakets, .NET Framework 4.7.2 mit C#.
Dies ist mein aktueller Code zum Festlegen der XMP-Metadaten für das PDF/A-Dokument, aber dieser Code funktioniert eigentlich nicht, weil ich ständig Fehlermeldungen bekomme, dass

iText.Kernel.XMP.XMPException: 'Schema-Namespace-URI und Präfix
nicht übereinstimmen'

Zum Beispiel in dieser Codezeile:
xmpMeta.SetStructField(extensionNamespace, schemaArrayItemPath, schemaNamespace, "schema", "Factur-X PDF/A Extension Schema");

Ich habe bereits ein funktionierendes Beispiel, in dem der Code nicht auf Ausnahmen stößt, aber wenn ich das PDF/A-Dokument mit veraPDF validiere, werden mir viele Fehler gemeldet, dass das PDF /A ist nicht konform. Gibt es kein Beispiel zum Festlegen gültiger XMP-Metadaten für ZUGFeRD-Rechnungen?
Dies ist mein aktueller Code:
byte[] xmpBytes = pdfaDoc.GetXmpMetadata();
XMPMeta xmpMeta;
if (xmpBytes != null && xmpBytes.Length > 0)
{
xmpMeta = XMPMetaFactory.ParseFromBuffer(xmpBytes);
}
else
{
xmpMeta = XMPMetaFactory.Create();
}
XMPMetaFactory.GetSchemaRegistry().RegisterNamespace("http://www.aiim.org/pdfa/ns/extension/", "pdfaExtension");
XMPMetaFactory.GetSchemaRegistry().RegisterNamespace("http://www.aiim.org/pdfa/ns/schema#", "pdfaSchema");
XMPMetaFactory.GetSchemaRegistry().RegisterNamespace("http://www.aiim.org/pdfa/ns/property#", "pdfaProperty");
XMPMetaFactory.GetSchemaRegistry().RegisterNamespace("urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#", "fx");

PropertyOptions arrayOptions = new PropertyOptions(PropertyOptions.ARRAY | PropertyOptions.ARRAY_ORDERED);
PropertyOptions structOptions = new PropertyOptions(PropertyOptions.STRUCT);

string extensionNamespace = "http://www.aiim.org/pdfa/ns/extension/";
string schemaNamespace = "http://www.aiim.org/pdfa/ns/schema#";
string propertyNamespace = "http://www.aiim.org/pdfa/ns/property#";
string zugferdNamespace = "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#";

xmpMeta.AppendArrayItem(extensionNamespace, "schemas", arrayOptions, null, null);

string schemaArrayItemPath = extensionNamespace + "schemas[1]";

xmpMeta.SetStructField(extensionNamespace, schemaArrayItemPath, schemaNamespace, "schema", "Factur-X PDF/A Extension Schema");
xmpMeta.SetStructField(extensionNamespace, schemaArrayItemPath, schemaNamespace, "namespaceURI", zugferdNamespace);
xmpMeta.SetStructField(extensionNamespace, schemaArrayItemPath, schemaNamespace, "prefix", "fx");

xmpMeta.SetStructField(extensionNamespace, schemaArrayItemPath, schemaNamespace, "property", null, arrayOptions);

string propertyArrayItemPath = schemaArrayItemPath + "/property[1]";

xmpMeta.AppendArrayItem(propertyNamespace, schemaArrayItemPath + "/property", structOptions, null, null);
xmpMeta.SetStructField(propertyNamespace, propertyArrayItemPath, propertyNamespace, "name", "ConformanceLevel");
xmpMeta.SetStructField(propertyNamespace, propertyArrayItemPath, propertyNamespace, "valueType", "Text");
xmpMeta.SetStructField(propertyNamespace, propertyArrayItemPath, propertyNamespace, "category", "external");
xmpMeta.SetStructField(propertyNamespace, propertyArrayItemPath, propertyNamespace, "description", "Conformance level of the invoice.");

xmpMeta.AppendArrayItem(propertyNamespace, schemaArrayItemPath + "/property", structOptions, null, null);
string secondPropertyPath = schemaArrayItemPath + "/property[2]";
xmpMeta.SetStructField(propertyNamespace, secondPropertyPath, propertyNamespace, "name", "DocumentType");
xmpMeta.SetStructField(propertyNamespace, secondPropertyPath, propertyNamespace, "valueType", "Text");
xmpMeta.SetStructField(propertyNamespace, secondPropertyPath, propertyNamespace, "category", "external");
xmpMeta.SetStructField(propertyNamespace, secondPropertyPath, propertyNamespace, "description", "Type of the document.");

Top