我想知道是否有办法创建链接(使用HTML)来打开嵌入在pdf文档中的附件。
像这样......
<a href="attachment.pdf">Open the attachment file</a> or <a href="file:///attachment.pdf">Open the attachment file</a>
有任何建议或建议吗?
由于
答案 0 :(得分:1)
在阅读了下一篇有用的帖子后,我已经能够实现这个场景
https://groups.google.com/forum/#!topic/flying-saucer-users/KuwPoTjaQYU
步骤:
这里是基于base64内容创建嵌入式文件的代码。
<强>爪哇强>
...String doEmbedFile = handler.getAttributeValue( elem, "data-fs-embed-file" );
if ("true".equals(doEmbedFile.toLowerCase())) {
String fileName = new File(uri).getName();
String content = handler.getAttributeValue( elem, "content" );
com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
if (targetArea == null) {
return;
}
try {
if (!_attachments.contains(fileName)) {
byte[] fileBytes = Base64.getDecoder().decode(content.getBytes("UTF-8"));
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(_writer, null, fileName, fileBytes);
fs.addDescription(fileName, true);
_writer.addFileAttachment(fs);
_attachments.add(fileName);
}
targetArea.setBorder(0);
targetArea.setBorderWidth(0);
//This only works on Adobe Acrobat Reader
PdfAction action = PdfAction.javaScript(
"this.exportDataObject({cName:\"" + fileName + "\", nLaunch:2});",
_writer
);...
<强> HTML 强>
<body><div id='div1'><p><a href='test.png' data-fs-embed-file='true' content='iVBORw0KGgoAAAANSUhEU...'>open test.png file</a></p></div><div id='div2'><p><a href='test.pdf' data-fs-embed-file='true' content='JVBERi0xLjUNCiW1tbW1D...'>open test.pdf file</a></p></div><div id='div3'><p><a href='test.txt' data-fs-embed-file='true' content='VEVFRUVFRUVFRVNUIFRYVA=='>open test.txt file</a></p></div></body>
* base64内容被截断
<强>输出强>
问候,我希望它可以帮助别人
答案 1 :(得分:0)
只需在新标签页上打开它,在锚标记中添加属性target =“_ blank”
<a href="http://link.to/file.pdf" target="_blank">Open attachment</a>