如何在前端展示后端返回的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+"'></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});
    },

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-02 19:32:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-02 19:32:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-02 19:32:05       82 阅读
  4. Python语言-面向对象

    2024-05-02 19:32:05       91 阅读

热门阅读

  1. 第二弹:走进CSS世界,学习记录

    2024-05-02 19:32:05       30 阅读
  2. 【C++】循环语句中引起的循环引用问题

    2024-05-02 19:32:05       37 阅读
  3. npm详解

    2024-05-02 19:32:05       39 阅读
  4. C++可变参数模板中的省略号

    2024-05-02 19:32:05       33 阅读
  5. 子查询

    2024-05-02 19:32:05       39 阅读
  6. 中了内存马如何排查(不死马)

    2024-05-02 19:32:05       32 阅读
  7. MyBatis-plus笔记——分页插件

    2024-05-02 19:32:05       33 阅读
  8. 【高并发解决思路】

    2024-05-02 19:32:05       37 阅读