你的研究是正确的。
嗯,主要是因为区分属于整个 pdf 文档的元数据和属于 TIFF 图像的元数据很重要。
第一个确实仅限于每个 pdf 的单个实例。
第二个独立于 pdf 元数据,但可以作为文件附件添加,这是 PDF/A-3 标准允许的。
这两种类型都独立于任何页面,因此从这个意义上说,您的老板的请求表明缺乏对 pdf 格式的了解。
但是,您可以在指向其元数据的每个 Tiff 上放置一个链接注释,可选择存储在第二个 pdf 文件中,从而产生数据以某种方式存在于页面上的错觉。
现在,我必须恭敬地不同意您关于 iText 没有为您提供处理此问题的工具的说法。 Chapter 7 of the iText7 Jumpstart tutorial 处理 PDF/A-X 的创建,包括嵌入文件。 PDF/A-3 是第三个例子。
对于链接注释,只要了解一些 Pdf-spec(嵌入式 Go-To Actions)和 iText 的低级操作方法,就可以实现。我现在没有现成的示例,但我会看看我是否可以酿造一些东西并稍后将其添加到这个答案中。
编辑:
好吧,这令人失望,Foxit 和 Adobe 的读者都不支持嵌入式 go-to 操作。不过,如果您有兴趣,下面是我使用 iText7 创建 PDF/A-3 兼容文档的代码,将元数据添加为单独的 Pdf。
public static String INTENT = "src/test/resources/StackOverflow/EmbeddedLinking/sRGB_CS_profile.icm";
public static String IMG = "src/test/resources/StackOverflow/EmbeddedLinking/itis.jpg";
public static String META = "target/output/StackOverflow/EmbeddedLinking/metadata.pdf";
public static String DEST = "target/output/StackOverFlow/EmbeddedLinking/embeddedMetaData.pdf";
public static void main(String[] args) throws IOException, java.io.IOException {
File file = new File(DEST);
file.getParentFile().mkdirs();
new EmbeddedLinking().createPdf(META);
new EmbeddedLinking().createPdfWithEmbeddedFile(DEST,META,IMG,INTENT);
}
public void createPdf(String dest) throws IOException, FileNotFoundException{
PdfWriter writer = new PdfWriter(dest);
PdfDocument pdfDoc = new PdfDocument(writer);
Document doc = new Document(pdfDoc);
//Put some data here
doc.add(new Paragraph("This is the metadata"));
doc.add(new Paragraph("The Cake is Lie"));
doc.add(new Paragraph("42"));
doc.add(new Paragraph("The Spice must flow"));
doc.close();
}
public void createPdfWithEmbeddedFile(String dest, String embeddedPath, String imgPath, String intent) throws java.io.IOException {
PdfWriter writer = new PdfWriter(dest);
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "","http://www.color.org", "sRGB IEC61966-2.1", new FileInputStream(intent));
PdfADocument pdfADoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3A,outputIntent);
//Setting some required parameters
pdfADoc.setTagged();
pdfADoc.getCatalog().setLang(new PdfString("en-US"));
pdfADoc.getCatalog().setViewerPreferences(
new PdfViewerPreferences().setDisplayDocTitle(true));
PdfDocumentInfo info = pdfADoc.getDocumentInfo();
info.setTitle("iText7 PDF/A-3 Embedded Go-To example");
//Add attachment
PdfDictionary parameters = new PdfDictionary();
parameters.put(PdfName.ModDate, new PdfDate().getPdfObject());
PdfFileSpec fileSpec = PdfFileSpec.createEmbeddedFileSpec(
pdfADoc, Files.readAllBytes(Paths.get(embeddedPath)), "metadata.pdf",
"metadata.pdf", new PdfName("application/pdf"), parameters,
PdfName.Data, false);
fileSpec.put(new PdfName("AFRelationship"), new PdfName("Data"));
pdfADoc.addFileAttachment("metadata.pdf", fileSpec);
PdfArray array = new PdfArray();
array.add(fileSpec.getPdfObject().getIndirectReference());
pdfADoc.getCatalog().put(new PdfName("AF"), array);
//Add Image
int imagePage = 1; //We know the image will end up on the first page since it's the only thing we add to the document
Document doc = new Document(pdfADoc, PageSize.A4);
Image img = new Image(ImageDataFactory.create(imgPath));
doc.add(img);
//Add link annotation to embedded file
float pageHeight = PageSize.A4.getHeight();
float imageWidth = img.getImageWidth();
float imageHeight = img.getImageHeight();
float x = doc.getLeftMargin();
float y = pageHeight - doc.getTopMargin() - imageHeight;
Rectangle linkAnnotationPosition = new Rectangle(x,y,imageWidth,imageHeight);
PdfLinkAnnotation linkAnnotation = new PdfLinkAnnotation(linkAnnotationPosition);
//Setup the Embedded GoTO action
PdfExplicitDestination explicitDestination = PdfExplicitDestination.createFit(imagePage);//Destination in the target file
PdfTargetDictionary targetDictionary = PdfTargetDictionary.createChildTarget("metadata.pdf"); //Target embedded file
PdfAction action = PdfAction.createGoToE(fileSpec,explicitDestination,true,targetDictionary);
linkAnnotation.setAction(action);
//PDF/A requires the presence of the F -bit flag array in every dictionary. The print flag needs to be 1, and some other flags 0.
//See the spec for details and options, but the bit pattern represented by the integer 4 suffices for conformance to PDF/A-3
int fBitArray = 4;
linkAnnotation.put(PdfName.F,new PdfNumber(fBitArray));
//Add annotation to page
pdfADoc.getPage(imagePage).addAnnotation(linkAnnotation);
//Close document
doc.close();
}