修改pdf元数据XMP

时间:2017-09-19 12:04:46

标签: java pdf itext xmp

我想使用iText或类似的库修改pdf中的现有元数据XMP。

我通过 com.itextpdf.text.pdf.PdfReader.getMetadata()获取xmp字符串 下面我们有例子xmp

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.2-c001 63.139439, 2010/09/27-13:37:26        ">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:dc="http://purl.org/dc/elements/1.1/">
         <dc:format>application/pdf</dc:format>
         <dc:identifier>10.1016/j.aipprr.2017.03.003</dc:identifier>
         <dc:title>
            <rdf:Alt>
               <rdf:li xml:lang="x-default">Prólogo</rdf:li>
            </rdf:Alt>
         </dc:title>
         <dc:creator>
            <rdf:Seq>
               <rdf:li>Rolando Díaz-Loving</rdf:li>
            </rdf:Seq>
         </dc:creator>
         <dc:description>
            <rdf:Alt>
               <rdf:li xml:lang="x-default">Acta de Investigación Psicológica , 7 (2017) 2559. doi:10.1016/j.aipprr.2017.03.003</rdf:li>
            </rdf:Alt>
         </dc:description>
         <dc:publisher>
            <rdf:Bag>
               <rdf:li>Universidad Nacional Autónoma de México, Facultad de Psicología</rdf:li>
            </rdf:Bag>
         </dc:publisher>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:prism="http://prismstandard.org/namespaces/basic/3.0/">
         <prism:aggregationType>journal</prism:aggregationType>
         <prism:publicationName>Acta de Investigación Psicológica </prism:publicationName>
         <prism:copyright>© 2017 Universidad Nacional Autónoma de México, Facultad de Psicología. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/).</prism:copyright>
         <prism:issn>2007-4719</prism:issn>
         <prism:volume>7</prism:volume>
         <prism:number>1</prism:number>
         <prism:coverDisplayDate>April 2017</prism:coverDisplayDate>
         <prism:pageRange>2559</prism:pageRange>
         <prism:startingPage>2559</prism:startingPage>
         <prism:doi>10.1016/j.aipprr.2017.03.003</prism:doi>
         <prism:url>http://dx.doi.org/10.1016/j.aipprr.2017.03.003</prism:url>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:crossmark="http://crossref.org/crossmark/1.0/">
         <crossmark:MajorVersionDate>2010-04-23</crossmark:MajorVersionDate>
         <crossmark:CrossmarkDomainExclusive>true</crossmark:CrossmarkDomainExclusive>
         <crossmark:DOI>10.1016/j.aipprr.2017.03.003</crossmark:DOI>
         <crossmark:CrossMarkDomains>
            <rdf:Seq>
               <rdf:li>elsevier.com</rdf:li>
               <rdf:li>sciencedirect.com</rdf:li>
            </rdf:Seq>
         </crossmark:CrossMarkDomains>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:jav="http://www.niso.org/schemas/jav/1.0/">
         <jav:journal_article_version>VoR</jav:journal_article_version>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:pdfx="http://ns.adobe.com/pdfx/1.3/">
         <pdfx:ElsevierWebPDFSpecifications>6.5</pdfx:ElsevierWebPDFSpecifications>
         <pdfx:doi>10.1016/j.aipprr.2017.03.003</pdfx:doi>
         <pdfx:robots>noindex</pdfx:robots>
         <pdfx:CrossmarkMajorVersionDate>2010-04-23</pdfx:CrossmarkMajorVersionDate>
         <pdfx:CrossmarkDomainExclusive>true</pdfx:CrossmarkDomainExclusive>
         <pdfx:CrossMarkDomainsↂ005B1ↂ005D>sciencedirect.com</pdfx:CrossMarkDomainsↂ005B1ↂ005D>
         <pdfx:CrossMarkDomainsↂ005B2ↂ005D>elsevier.com</pdfx:CrossMarkDomainsↂ005B2ↂ005D>
         <pdfx:CrossMarkDomains>
            <rdf:Seq>
               <rdf:li>sciencedirect.com</rdf:li>
               <rdf:li>elsevier.com</rdf:li>
            </rdf:Seq>
         </pdfx:CrossMarkDomains>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:xmp="http://ns.adobe.com/xap/1.0/">
         <xmp:CreatorTool>Elsevier</xmp:CreatorTool>
         <xmp:ModifyDate>2017-05-25T20:23:38-05:00</xmp:ModifyDate>
         <xmp:CreateDate>2017-05-03T16:07:41Z</xmp:CreateDate>
         <xmp:MetadataDate>2017-05-25T20:23:38-05:00</xmp:MetadataDate>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/">
         <xmpRights:Marked>True</xmpRights:Marked>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
         <pdf:Trapped>True</pdf:Trapped>
         <pdf:Producer>Acrobat Distiller 9.0.0 (Windows)</pdf:Producer>
         <pdf:Keywords/>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
         <xmpMM:DocumentID>uuid:9d0cc73b-66d9-4125-9685-0f38e1653c8b</xmpMM:DocumentID>
         <xmpMM:InstanceID>uuid:a666df63-92f4-44d1-8d4a-4a61bc95b979</xmpMM:InstanceID>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:ali="http://www.niso.org/schemas/ali/1.0/">
         <ali:license_ref>
            <rdf:Bag>
               <rdf:li rdf:parseType="Resource">
                  <ali:uri>http://creativecommons.org/licenses/by-nc-nd/4.0/</ali:uri>
               </rdf:li>
            </rdf:Bag>
         </ali:license_ref>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>                      
<?xpacket end="w"?>

现在我想用当前时间戳修改<xmp:ModifyDate>2017-05-25T20:23:38-05:00</xmp:ModifyDate>,但实际上我不知道怎么做而没有字面上的字符串解析。是否有任何库允许修改xmp?

1 个答案:

答案 0 :(得分:0)

最后我使用了iText库中的XmpReader.replaceNode。