// response 就是后端返回的base64文件的字符串
const fileData = atob(response);
var arrayBuffer = new ArrayBuffer(fileData.length);
var uint8Array = new Uint8Array(arrayBuffer);
for (var i = 0; i < fileData.length; i++) {
uint8Array[i] = fileData.charCodeAt(i);
}
var blob = new Blob([arrayBuffer], { type: "application/pdf" });
var url = URL.createObjectURL(blob);
// 弹窗打开
var iframe = document.createElement("iframe");
iframe.src = url;
window.open(iframe.src)
// 或者往当前页面增加一个iframe
var embed = document.createElement('embed');
embed.src = url;
document.body.appendChild(embed);
前端如何处理后端返回的base64的PDF文件流
最新推荐文章于 2024-06-25 16:57:26 发布