【发布时间】:2020-01-23 17:19:55
【问题描述】:
我正在开发一个项目,该项目将 http 请求发送到 spring boot。作为响应,我收到一个带有 PDF 文件的流。我需要使用 Chrome PDF 查看器的所有功能在新选项卡中打开此文件,尤其是下载。
这是我处理响应并使用收到的 PDF 文件打开新标签的代码:
fetch(options.url, options)
.then(response => {
return response.blob();
})
.then(blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = () => {
const data = reader.result
const tab = window.open();
tab.document.write("<html>" +
"<body>" +
"<embed type='application/pdf' " +
"style='position:absolute; left: 0; top: 0;' " +
"width='100%' " +
"height='100%' " +
"src='" + data +"'/>" +
"</body>" +
"</html>")
}
})
但打开新标签后出现问题:Chrome PDF 查看器的所有按钮都可以正常工作,但“下载”按钮除外。
点击按钮后没有任何反应。
你有解决这个问题的想法吗?
【问题讨论】:
标签: javascript html pdf