html2Canvas+JsPDF 导出pdf 无法显示网络图片

html2Canvas+JsPDF 导出pdf

问题:类似于下面着这种网络图片使用img导出的时候是空白的

https://gimg3.baidu.com/search/src=http%3A%2F%2Fpics4.baidu.com%2Ffeed%2F7e3e6709c93d70cf827fb2fda054500cb8a12bc9.jpeg%40f_auto%3Ftoken%3Dd97d3f0fd06e680e592584f8c7a24ac8\&refer=http%3A%2F%2Fwww.baidu.com\&app=2021\&size=f360,240\&n=0\&g=0n\&q=75\&fmt=auto?sec=1690045200\&t=e1a88c44b1b9907677400a079766e0bf

解决:将网络图片转成base64

复制代码
<img :src="aaa" style="width:200px" alt="">

转base64
let res = await this.getBase64Image('https://gimg3.baidu.com/search/src=http%3A%2F%2Fpics4.baidu.com%2Ffeed%2F7e3e6709c93d70cf827fb2fda054500cb8a12bc9.jpeg%40f_auto%3Ftoken%3Dd97d3f0fd06e680e592584f8c7a24ac8&refer=http%3A%2F%2Fwww.baidu.com&app=2021&size=f360,240&n=0&g=0n&q=75&fmt=auto?sec=1690045200&t=e1a88c44b1b9907677400a079766e0bf')
this.aaa = res

getBase64Image(src) {
      return new Promise(resolve => {
        const img = new Image()
        img.crossOrigin = ''
        img.src = src
        img.onload = function() {
          const canvas = document.createElement('canvas')
          canvas.width = img.width
          canvas.height = img.height
          const ctx = canvas.getContext('2d')
          ctx && ctx.drawImage(img, 0, 0, img.width, img.height)
          const ext = img.src.substring(img.src.lastIndexOf('.') + 1).toLowerCase()
          const dataURL = canvas.toDataURL('image/' + ext)
          resolve(dataURL)
        }
      })
    },

导出

相关推荐
这个需求建议不做19 小时前
pdf.js(pdfdist)踩坑workerSrc报错pdf.worker.mjs无法正确获取
开发语言·javascript·pdf
坐吃山猪19 小时前
Python之PDF小工具
开发语言·python·pdf
极智-99621 小时前
pdf怎么打开?【图文详解】免费的pdf阅读编辑器?pdf文件转换?
pdf·pdf转换·pdf转word·pdf编辑·pdf文件怎么打开·pdf阅读编辑·pdf文件阅读
maogewang2 天前
清朝条约史料三册合辑:从尼布楚到辛丑条约的完整 PDF 文献汇编
pdf
开开心心就好2 天前
版本转换工具,支持Win双系统零售批量版
linux·运维·服务器·pdf·散列表·零售·1024程序员节
DechinPhy2 天前
使用Python免费合并PDF文件
开发语言·数据库·python·mysql·pdf
开开心心就好2 天前
免费卸载工具,可清理残留批量管理启动项
linux·运维·服务器·windows·随机森林·pdf·1024程序员节
mysusheng3 天前
2025年12月Z-Library电子书下载工具
pdf
vfvfb3 天前
pdf转图片 每一页转成图片 pdf转jpg
pdf·pdf每一页转成图片
YJlio3 天前
Python 一键拆分 PDF:按“目录/章节”建文件夹 + 每页单独导出(支持书签识别&正文识别)
开发语言·python·pdf