feat: dix all pdf problems. Validator now green
This commit is contained in:
+101
-8
@@ -11,27 +11,120 @@ const (
|
||||
FacturXPrefix = "fx:"
|
||||
)
|
||||
|
||||
type PDFAProperty struct {
|
||||
Name string `xmp:"pdfaProperty:name"`
|
||||
ValueType string `xmp:"pdfaProperty:valueType"`
|
||||
Category string `xmp:"pdfaProperty:category"`
|
||||
Description string `xmp:"pdfaProperty:description"`
|
||||
}
|
||||
|
||||
type PDFASchema struct {
|
||||
Schema string `xmp:"pdfaSchema:schema"`
|
||||
NamespaceURI string `xmp:"pdfaSchema:namespaceURI"`
|
||||
Prefix string `xmp:"pdfaSchema:prefix"`
|
||||
Property []PDFAProperty `xmp:"pdfaSchema:property"`
|
||||
}
|
||||
|
||||
type PDFAExtensionData struct {
|
||||
Schemas [1]PDFASchema `xmp:"pdfaExtension:schemas,bag"`
|
||||
}
|
||||
|
||||
type PDFAExtensionModel struct {
|
||||
PDFAExtensionData
|
||||
|
||||
xmpbase.XmpBase
|
||||
}
|
||||
|
||||
func (x PDFAExtensionModel) Can(nsName string) bool {
|
||||
return nsName == "pdfaExtension"
|
||||
}
|
||||
|
||||
func (x PDFAExtensionModel) Namespaces() xmp.NamespaceList {
|
||||
return xmp.NamespaceList{
|
||||
{
|
||||
Name: "pdfaSchema",
|
||||
URI: "http://www.aiim.org/pdfa/ns/schema#",
|
||||
Factory: defaultFactory,
|
||||
},
|
||||
{
|
||||
Name: "pdfaExtension",
|
||||
URI: "http://www.aiim.org/pdfa/ns/extension/",
|
||||
Factory: defaultFactory,
|
||||
},
|
||||
{
|
||||
Name: "pdfaProperty",
|
||||
URI: "http://www.aiim.org/pdfa/ns/property#",
|
||||
Factory: defaultFactory,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func defaultFactory(name string) xmp.Model {
|
||||
return nil
|
||||
}
|
||||
|
||||
func addFacturXXmpData(data []byte) ([]byte, error) {
|
||||
// --- Register Factur-X namespace ---
|
||||
xmp.Register(&xmp.Namespace{
|
||||
Name: "fx",
|
||||
URI: FacturXUri,
|
||||
Factory: defaultFactory,
|
||||
})
|
||||
|
||||
doc := &xmp.Document{}
|
||||
err := xmp.Unmarshal(data, doc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// --- Register Factur-X namespace ---
|
||||
ns := &xmp.Namespace{
|
||||
Name: "fx",
|
||||
URI: FacturXUri,
|
||||
Factory: func(name string) xmp.Model {
|
||||
return &xmpbase.XmpBase{}
|
||||
model := &PDFAExtensionModel{
|
||||
PDFAExtensionData: PDFAExtensionData{
|
||||
Schemas: [1]PDFASchema{
|
||||
{
|
||||
Schema: "Factur-X PDFA Extension Schema",
|
||||
NamespaceURI: "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#",
|
||||
Prefix: "fx",
|
||||
Property: []PDFAProperty{
|
||||
{
|
||||
Name: "DocumentType",
|
||||
ValueType: "Text",
|
||||
Category: "external",
|
||||
Description: "Factur-X document type",
|
||||
},
|
||||
{
|
||||
Name: "DocumentFileName",
|
||||
ValueType: "Text",
|
||||
Category: "external",
|
||||
Description: "Attached XML file name",
|
||||
},
|
||||
{
|
||||
Name: "Version",
|
||||
ValueType: "Text",
|
||||
Category: "external",
|
||||
Description: "Factur-X version",
|
||||
},
|
||||
{
|
||||
Name: "ConformanceLevel",
|
||||
ValueType: "Text",
|
||||
Category: "external",
|
||||
Description: "Factur-X profile",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
xmp.Register(ns)
|
||||
_, err = doc.MakeModel(ns)
|
||||
_, err = doc.AddModel(model)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doc.FindModel(&xmp.Namespace{
|
||||
Name: "",
|
||||
URI: "",
|
||||
Factory: nil,
|
||||
})
|
||||
|
||||
// --- Set Factur-X properties ---
|
||||
err = doc.SetPath(xmp.PathValue{
|
||||
Path: FacturXPrefix + "ConformanceLevel",
|
||||
|
||||
Reference in New Issue
Block a user