如何在前端展示后端返回的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});
    },
相关推荐
Moment3 小时前
腾讯终于对个人开放了,5 分钟在 QQ 里养一只「真能干活」的 AI 😍😍😍
前端·后端·github
比尔盖茨的大脑3 小时前
AI Agent 架构设计:从 ReAct 到 Multi-Agent 系统
前端·人工智能·全栈
天才熊猫君3 小时前
使用 Vite Mode 实现客户端与管理端的物理隔离
前端
HelloReader3 小时前
React Hook 到底是干嘛的?
前端
用户60572374873083 小时前
OpenSpec 实战:从需求到代码的完整工作流
前端·后端·程序员
寅时码3 小时前
React 正在演变为一场不可逆的赛博瘟疫:AI 投毒、编译器迷信与装死的官方
前端·react.js·设计模式
忆江南4 小时前
HTTP 各版本演进与 HTTPS 原理详解
前端
忆江南4 小时前
对组件化与模块化的思考与总结
前端
小码哥_常4 小时前
从0到1:Android组件化架构搭建秘籍
前端