1

我必须使用带有附件的 iText 创建 PDF/A-3-B(ISO 19005-3:2012。第 3 部分)。

如何在 PDF 的文档目录中创建 AF 条目?

我在这个问题的末尾使用了 Java 代码来生成模拟测试。使用 Adob​​e XI Pro Preflight,我看到 PDF 的结构变成了这样:

The document catalog root
   AF:
      0: (6)   /T:FileSpec

但结构应该是:

The document catalog root
   AF:
      0: (6) [6 0 R]   /T:FileSpec

换句话说,我认为 AF 条目应该是指向附件本身的指针。

ISO 说:

KEY:   AF
TYPE:  array of dictionaries
Value: (Optional) An array of File Specification Dictionaries 
       representing the source content from which this document is 
       derived or data used to produce the visual representation.

可用于生成示例的模拟 Java 代码如下:

public static final String RESULT = "target/pdfa3.pdf";
public static final String FONTPATH = "/usr/share/fonts/truetype/msttcorefonts/times.ttf";
private static Font FONT = FontFactory.getFont(FONTPATH, BaseFont.CP1252, BaseFont.EMBEDDED);

public void test(){
   //creating document
   Document document = new Document();
   PdfAWriter writer = PdfAWriter.getInstance(document, new FileOutputStream(RESULT), PdfAConformanceLevel.PDF_A_3B);

   //creating default Xmp
   writer.createXmpMetadata();

   document.open();

   //adding attachment as embedded file
   PdfDictionary fileParameter = new PdfDictionary();
   fileParameter.put(new PdfName("ModDate"), new PdfString("2013-01-09T16:28-02:00"));
   PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, src.getAbsolutePath(), src.getName(), null, false, "image/jpeg", fileParameter);
   fs.put(new PdfName("AFRelationship"), new PdfName("Source"));
   writer.addFileAttachment(src.getName().substring(0, src.getName().indexOf('.')), fs);

   //???????????????????
   //THIS IS THE POINT: HOW TO ADD AN AF ENTRY?
   //this does not work:
   writer.getExtraCatalog().put(new PdfName("AF"), new PdfArray(fs));
   //???????????????????

   //adding some text
   document.add(new Paragraph("Hello World!", FONT));

   //done!
   document.close();
}
4

0 回答 0