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

nbewdwxp  于 2024-01-05  发布在  Java
关注(0)|答案(1)|浏览(203)

我必须使用带附件的iText创建PDF/A-3-B(ISO 19005-3:2012. Part 3)。
如何在PDF的文档目录中创建AF条目?
我在这个问题的结尾使用Java代码来生成一个模拟测试。使用Adobe Xi Pro Preflight,我看到PDF的结构变成了这样:

  1. The document catalog root
  2. AF:
  3. 0: (6) /T:FileSpec

字符串
但结构应该是:

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


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

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


可以用来生成示例的mock Java代码如下:

  1. public static final String RESULT = "target/pdfa3.pdf";
  2. public static final String FONTPATH = "/usr/share/fonts/truetype/msttcorefonts/times.ttf";
  3. private static Font FONT = FontFactory.getFont(FONTPATH, BaseFont.CP1252, BaseFont.EMBEDDED);
  4. public void test(){
  5. //creating document
  6. Document document = new Document();
  7. PdfAWriter writer = PdfAWriter.getInstance(document, new FileOutputStream(RESULT), PdfAConformanceLevel.PDF_A_3B);
  8. //creating default Xmp
  9. writer.createXmpMetadata();
  10. document.open();
  11. //adding attachment as embedded file
  12. PdfDictionary fileParameter = new PdfDictionary();
  13. fileParameter.put(new PdfName("ModDate"), new PdfString("2013-01-09T16:28-02:00"));
  14. PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, src.getAbsolutePath(), src.getName(), null, false, "image/jpeg", fileParameter);
  15. fs.put(new PdfName("AFRelationship"), new PdfName("Source"));
  16. writer.addFileAttachment(src.getName().substring(0, src.getName().indexOf('.')), fs);
  17. //???????????????????
  18. //THIS IS THE POINT: HOW TO ADD AN AF ENTRY?
  19. //this does not work:
  20. writer.getExtraCatalog().put(new PdfName("AF"), new PdfArray(fs));
  21. //???????????????????
  22. //adding some text
  23. document.add(new Paragraph("Hello World!", FONT));
  24. //done!
  25. document.close();
  26. }

dy1byipe

dy1byipe1#

你现在(或者说很多年前)直接将PdfFileSpecification fs对象传递给new PdfArray。你应该传递一个对它的引用:

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

字符串
查看更多完整答案https://stackoverflow.com/a/21020431/326162

相关问题