【发布时间】:2014-07-16 13:33:09
【问题描述】:
我目前正在使用 Play! 开发 Java 应用程序!框架 2。 在某些页面中,我需要在我的服务器上生成一个 PDF 文件,然后将其发送到浏览器并在 iframe 或嵌入标签上显示。
我正在使用 Play 将文件发送到客户端!结果机制:
File resultFile = new File(outputFilePath);
response().setHeader("Content-Length", Long.toString(resultFile.length()));
return ok(resultFile).as("application/pdf");
在客户端,我收到文件,并使用createObjectUrl 来获取要传递给我的 iframe 的 URL
window.URL = window.URL || window.webkitURL;
var file = new window.Blob([result], { type: 'application/pdf' });
var fileUrl = window.URL.createObjectURL(file);
$("#displayDoc").attr("data", fileUrl);
所有这一切的结果很奇怪:iFrame 显示出来,显示的页面与我的文档中的页面一样多,但所有页面都是空的。我在 Chrome 的 Dev Tools 插件上收到此错误:
resource interpreted as document but transferred with mime type application/pdf chrome
有人知道发生了什么吗?
谢谢!
劳里斯
【问题讨论】:
标签: javascript iframe playframework pdf-generation