iText - 如何在 PDF_A_3B - PDF/A-3 B 的文档目录中创建 AF 条目

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

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

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

我使用了本问题末尾的Java代码来生成模拟测试。使用 Adobe 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();
}
java pdf pdf-generation itext
1个回答
0
投票

您(或者很多年前曾经)直接将

PdfFileSpecification fs
对象传递给
new PdfArray
。 您应该传递对它的引用:

writer.getExtraCatalog().put(new PdfName("AF"), 
                             new PdfArray(fs.getReference()));

在此处查看更完整的答案https://stackoverflow.com/a/21020431/326162

© www.soinside.com 2019 - 2024. All rights reserved.