我必须使用带附件的iText创建PDF/A-3-B(ISO 19005-3:2012. Part 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.
型
可以用来生成示例的mock 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();
}
型
1条答案
按热度按时间dy1byipe1#
你现在(或者说很多年前)直接将
PdfFileSpecification fs
对象传递给new PdfArray
。你应该传递一个对它的引用:字符串
查看更多完整答案https://stackoverflow.com/a/21020431/326162