如何在前端展示后端返回的pdf Base64格式字符串

文章目录

  • [如何在前端展示后端返回的pdf Base64格式字符串](#如何在前端展示后端返回的pdf Base64格式字符串)

如何在前端展示后端返回的pdf Base64格式字符串

js 复制代码
// fileBase64 就是后端返回的 pdf Base64格式字符串
    getPdfDocument(fileBase64) {
          let fileBlob = this.base64ToBlobsdf(fileBase64,'application/pdf');
          let basePdfUrl = window.URL.createObjectURL(fileBlob);
          sessionStorage.setItem('basePdfUrl', basePdfUrl);
          location.href = "lookPdf.html";
          let newWindow = window.open("");
          newWindow.document.write("<iframe width='100%' height='100%' src='"+basePdfUrl+"'></iframe>");
        }
      })
    },
    base64ToBlobsdf(fileBase64,fileType){
      let raw = window.atob(fileBase64);
      let rawLength = raw.length;
      let uint8Array = new Uint8Array(rawLength);
      while (rawLength--){
        uint8Array[rawLength] = raw.charCodeAt(rawLength);
      }
      return new Blob([uint8Array],{type: fileType});
    },
相关推荐
我是苏苏32 分钟前
Web开发:C#通过ProcessStartInfo动态调用执行Python脚本
java·服务器·前端
无羡仙1 小时前
Vue插槽
前端·vue.js
用户6387994773052 小时前
每组件(Per-Component)与集中式(Centralized)i18n
前端·javascript
SsunmdayKT2 小时前
React + Ts eslint配置
前端
开始学java2 小时前
useEffect 空依赖 + 定时器 = 闭包陷阱?count 永远停在 1 的坑我踩透了
前端
zerosrat2 小时前
从零实现 React Native(2): 跨平台支持
前端·react native
狗哥哥2 小时前
🔥 Vue 3 项目深度优化之旅:从 787KB 到极致性能
前端·vue.js
青莲8432 小时前
RecyclerView 完全指南
android·前端·面试
青莲8432 小时前
Android WebView 混合开发完整指南
android·前端·面试
GIS之路2 小时前
GDAL 实现矢量数据转换处理(全)
前端