且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将字节数组转换为pdf并下载

更新时间:2023-11-15 18:10:46

响应中的字符串似乎是Base-64编码的(参考小提琴)。您可以使用 fetch()(或旧版浏览器的 XMLHttpRequest())对其进行解码:

The string from the response seem to be Base-64 encoded (ref. fiddle). You can decode it using fetch() (or XMLHttpRequest() for older browsers):

fetch("data:application/pdf;base64," + response.data)
  .then(function(resp) {return resp.blob()})
  .then(function(blob) {
    FileSaver.saveAs(blob, 'foo.pdf')
  });