原生js解决base64转pdf

前提:base64转码前就是pdf格式

		let base=''//你要传入的base64数据
		let bstr = atob(base64)
        let n = bstr.length;
        let u8arr = new Uint8Array(n);
        while (n--) {u8arr[n] = bstr.charCodeAt(n);}
        //确定解析格式,可能可以变成img,没有深入研究
        let blob = new Blob([u8arr], {type: 'application/pdf;chartset=UTF-8'});
        let url = window.URL.createObjectURL(blob)
        //在新窗口打开该pdf用这个
         window.open(url)
         //下载dpf用这个
         const a = document.createElement('a')
       	 a.href = url
   	     a.download = name + '.pdf'
         document.body.appendChild(a)
         a.click()
         document.body.removeChild(a)
         //删除url绑定
        window.URL.revokeObjectURL(url)

版权声明:本文为zz_LXW原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。