当使用itext7从头开始创建PDF / A时,总是将以下内容添加到XMP元数据中:

<rdf:Description rdf:about=""
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
    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#"
    xmlns:xmp="http://ns.adobe.com/xap/1.0/"
    xmlns:pdfuaid="http://www.aiim.org/pdfua/ns/id/"
    xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/"
  dc:format="application/pdf"
  pdf:Producer="iText® 7.0.3-SNAPSHOT ©2000-2017 iText Group NV (AGPL-version)"
  xmp:CreateDate="2017-05-09T15:02:05+02:00"
  xmp:ModifyDate="2017-05-09T15:02:05+02:00"
  pdfaid:part="2"
  pdfaid:conformance="A">


我需要明确地不设置xmp:ModifyDate。
我尝试将其从目录中删除,但无济于事:

PdfADocument pdf = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, OutputIntent);
Document document = new Document(pdf);
... add content to pdf ...
pdf.getCatalog().remove(PdfName.ModDate);
document.close();
writer.close();


但是,xmp:ModifyDate仍显示在XMP元数据中。

有没有办法确保仅添加xmp:CreateDate?

最佳答案

我将向您展示两种避免在元数据中添加ModifyDate的方法。

第一个,如果在关闭文档之前通过PdfDocumentInfo

doc.getDocumentInfo().setMoreInfo(PdfName.ModDate.getValue(), null);
doc.close();


第二种方法更加灵活,通过覆盖updateXmpMetadata / PdfDocument中的PdfADocument方法来完成:

@Override
protected void updateXmpMetadata() {
    // Do not forget to call the method of the base class!
    super.updateXmpMetadata();
    try {
        XMPMeta meta = XMPMetaFactory.parseFromBuffer(getXmpMetadata(true));
        // Here we remove the unwanted entry from the metadata
        meta.deleteProperty(XMPConst.NS_XMP, PdfConst.ModifyDate);
        setXmpMetadata(meta);
    } catch (XMPException e) {
    }
}

10-08 16:15