reactjs - 我尝试显示 PDF,但我总是看到一个空白页面
问题描述
我徒劳地尝试显示通过 REST 接口发送的 PDF 文件。BLOB 在那里,不是空的。我总是得到一个空的PDF。没有错误。
const getPdf = (id) => {
const fetchData = async () => {
const data = await axios
.get("http://XXXXXX:xxx/xx/xx", {
params: {
_id: id,
gesuchtNach: wert,
firmenId: "555",
kundenId: "123",
},
})
.then(function (response) {
var blob = new Blob([response.data], { type: "application/pdf" });
var link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = "Report_" + new Date() + ".pdf";
link.click();
/* ALSO TRIED - SAME PROBLEM
const file = new Blob([response.data], { type: "application/pdf" });
FileSaver.saveAs(file, "file.pdf");
*/
})
.catch(function (error) {
console.log(error);
});
};
fetchData();
};
解决方案
推荐阅读
- c# - 返回匿名 2 字符串类型的通用列表的返回类型是什么?
- java - 如何在 install4j for Linux 包中减少 OpenJDK 11 捆绑的 JRE?
- windows - 编码 HRESULT 值:使用 FACILITY_ITF 还是设置位 29?
- c - C中的动态链接库
- c - 没有`...`的可变参数函数
- sql - 正确查询以返回 1 行,而不是在许多列中的 2 列不变时重复
- python - 从提取的 JSON 数据中追加和/或写入 CSV
- reactjs - ReactJS:谷歌地图(给出无效值错误)
- node.js - 如何通过使用 npm 安装软件包来解决此错误?
- javascript - 用动态长度数组替换多个子字符串的更好方法?