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

作者 : admin 本文共693个字,预计阅读时间需要2分钟 发布时间: 2024-06-9 共1人阅读

文章目录

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

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

// 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+"'>");
        }
      })
    },
    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});
    },
本站无任何商业行为
个人在线分享 » 如何在前端展示后端返回的pdf Base64格式字符串
E-->