如何在 iText 7 中将具有嵌套结构的数组添加到 PDF/A 的 XMP

问题描述 投票:0回答:1

我必须将一些 XMP 数据添加到 PDF/A-3 文件中。

这是我要添加的XMP数据:

<pdfaExtension:schemas>
    <rdf:Bag>
       <rdf:li rdf:parseType="Resource">
          <pdfaSchema:schema>Factur-X PDFA Extension Schema</pdfaSchema:schema>
          <pdfaSchema:namespaceURI>urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#</pdfaSchema:namespaceURI>
          <pdfaSchema:prefix>fx</pdfaSchema:prefix>
          <pdfaSchema:property>
             <rdf:Seq>
                <rdf:li rdf:parseType="Resource">
                   <pdfaProperty:name>DocumentFileName</pdfaProperty:name>
                   <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                   <pdfaProperty:category>external</pdfaProperty:category>
                   <pdfaProperty:description>name of the embedded XML invoice file</pdfaProperty:description>
                </rdf:li>
                <rdf:li rdf:parseType="Resource">
                   <pdfaProperty:name>DocumentType</pdfaProperty:name>
                   <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                   <pdfaProperty:category>external</pdfaProperty:category>
                   <pdfaProperty:description>INVOICE</pdfaProperty:description>
                </rdf:li>
                <rdf:li rdf:parseType="Resource">
                   <pdfaProperty:name>Version</pdfaProperty:name>
                   <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                   <pdfaProperty:category>external</pdfaProperty:category>
                   <pdfaProperty:description>The actual version of the ZUGFeRD XML schema</pdfaProperty:description>
                </rdf:li>
                <rdf:li rdf:parseType="Resource">
                   <pdfaProperty:name>ConformanceLevel</pdfaProperty:name>
                   <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                   <pdfaProperty:category>external</pdfaProperty:category>
                   <pdfaProperty:description>The selected ZUGFeRD profile completeness</pdfaProperty:description>
                </rdf:li>
             </rdf:Seq>
          </pdfaSchema:property>
       </rdf:li>
    </rdf:Bag>
</pdfaExtension:schemas>

它是一个包含一个结构体的数组,而该结构体又包含另一个结构体数组

我尝试了以下方法:

  1. 创建 XMP 元数据
XMPMeta xmpMeta = XMPMetaFactory.create();
  1. 添加数组
xmpMeta.appendArrayItem(XMPConst.NS_PDFA_EXTENSION, "schemas", new PropertyOptions(PropertyOptions.ARRAY), "schema", null);
  1. 将元数据添加到我的 PDF 文档
pdfDocument.setXmpMetadata(xmpMeta);

通过这样做,我得到以下结果:

<pdfaExtension:schemas>
    <rdf:Bag>
        <rdf:li>schema</rdf:li>
    </rdf:Bag>
</pdfaExtension:schemas>

如何将结构节点添加到该数组中?

我尝试编写数组项路径并向其中添加结构:

String path = XMPPathFactory.composeArrayItemPath("schemas", 1);

xmpMeta.setStructField(XMPConst.NS_PDFA_EXTENSION, path, XMPConst.NS_PDFA_SCHEMA, "namespaceURI", "Factur-X PDFA Extension Schema", new PropertyOptions(PropertyOptions.STRUCT));

但我得到 XMPException“结构和数组不能有值”

不幸的是我找不到太多关于 iText 和 XMP 的信息。

java arrays pdf itext7 xmp
1个回答
0
投票

最终的 XMA 数据应该如下所示。

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 7.1-c000 79.cb7c5a1, 2022/04/14-05:22:35        ">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about="xmpmeta"
            xmlns:dc="http://purl.org/dc/elements/1.1/"
            xmlns:fx="urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#"
            xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
            xmlns:xmp="http://ns.adobe.com/xap/1.0/"
            xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/"
            xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/"
            xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/"
            xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#"
            xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#">
         <dc:format>application/pdf</dc:format>
         <dc:creator>
            <rdf:Seq>
               <rdf:li>My Name</rdf:li>
            </rdf:Seq>
         </dc:creator>
         <dc:date>
            <rdf:Seq>
               <rdf:li>2024-04-24T10:46:15.682+02:00</rdf:li>
            </rdf:Seq>
         </dc:date>
         <dc:rights>
            <rdf:Alt>
               <rdf:li xml:lang="x-default">My Company</rdf:li>
            </rdf:Alt>
         </dc:rights>
         <dc:title>
            <rdf:Alt>
               <rdf:li xml:lang="x-default">RA 0123108157</rdf:li>
            </rdf:Alt>
         </dc:title>
         <fx:ConformanceLevel>EN 16931</fx:ConformanceLevel>
         <fx:DocumentFileName>factur-x.xml</fx:DocumentFileName>
         <fx:DocumentType>INVOICE</fx:DocumentType>
         <fx:Version>1.0</fx:Version>
         <pdf:Producer>My Company</pdf:Producer>
         <xmp:CreatorTool>HCL® Notes 14.0</xmp:CreatorTool>
         <xmp:CreateDate>2024-04-24T10:46:15+02:00</xmp:CreateDate>
         <xmp:ModifyDate>2024-04-24T10:46:15+02:00</xmp:ModifyDate>
         <xmpRights:Marked>True</xmpRights:Marked>
         <pdfaid:part>3</pdfaid:part>
         <pdfaid:conformance>B</pdfaid:conformance>
         <pdfaExtension:schemas>
            <rdf:Bag>
               <rdf:li rdf:parseType="Resource">
                  <pdfaSchema:namespaceURI>urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#</pdfaSchema:namespaceURI>
                  <pdfaSchema:prefix>fx</pdfaSchema:prefix>
                  <pdfaSchema:schema>Factur-X PDF/A Extension Schem</pdfaSchema:schema>
                  <pdfaSchema:property>
                     <rdf:Seq>
                        <rdf:li rdf:parseType="Resource">
                           <pdfaProperty:category>external</pdfaProperty:category>
                           <pdfaProperty:description>name of the embedded XML invoice file</pdfaProperty:description>
                           <pdfaProperty:name>DocumentFileName</pdfaProperty:name>
                           <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                        </rdf:li>
                        <rdf:li rdf:parseType="Resource">
                           <pdfaProperty:category>external</pdfaProperty:category>
                           <pdfaProperty:description>INVOICE</pdfaProperty:description>
                           <pdfaProperty:name>DocumentType</pdfaProperty:name>
                           <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                        </rdf:li>
                        <rdf:li rdf:parseType="Resource">
                           <pdfaProperty:category>external</pdfaProperty:category>
                           <pdfaProperty:description>The actual version of the Factur-X XML schema</pdfaProperty:description>
                           <pdfaProperty:name>Version</pdfaProperty:name>
                           <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                        </rdf:li>
                        <rdf:li rdf:parseType="Resource">
                           <pdfaProperty:category>external</pdfaProperty:category>
                           <pdfaProperty:description>The conformance level of the embedded Factur-X data</pdfaProperty:description>
                           <pdfaProperty:name>ConformanceLevel</pdfaProperty:name>
                           <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                        </rdf:li>
                     </rdf:Seq>
                  </pdfaSchema:property>
               </rdf:li>
            </rdf:Bag>
         </pdfaExtension:schemas>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>                    
<?xpacket end="w"?>
© www.soinside.com 2019 - 2024. All rights reserved.