【发布时间】:2018-07-27 07:24:44
【问题描述】:
我有一个将文件附加到 PDF 文件的代码。
PDDocument doc = new PDDocument();
PDPage page = new PDPage();
doc.addPage(page);
// read attachment file
File file = new File("/Users/TMac/Projects/Web/dir/index.html");
FileInputStream inputStream = new FileInputStream(file);
PDEmbeddedFile pdEmbeddedFile = new PDEmbeddedFile(doc, inputStream );
pdEmbeddedFile.setSubtype( "application/octet-stream" );
PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setEmbeddedFile( pdEmbeddedFile );
fs.setFile("index.html");
int offsetX = 20;
int offsetY = 600;
PDAnnotationFileAttachment txtLink = new PDAnnotationFileAttachment();
txtLink.setFile(fs);
// Set the rectangle containing the link
PDRectangle position = new PDRectangle();
position.setLowerLeftX(offsetX);
position.setLowerLeftY(offsetY);
position.setUpperRightX(offsetX + 20);
position.setUpperRightY(offsetY + 20);
txtLink.setRectangle(position);
page.getAnnotations().add(txtLink);
doc.save("/Users/TMac/Projects/PDF/outputFiles/testHTML.pdf");
doc.close();
问题是附件图标是这样的:
我需要用自定义图像替换这个图标。我找到了一些与文本链接相关的示例。当我单击该图像时,它应该打开该文件。附件代码(上面的代码)工作正常。如何将自定义图像添加为缩略图?
【问题讨论】:
标签: java pdf pdf-generation pdfbox