html转PDF进行下载

需要引入html2canvas.js 以及 jspdf.js

    downloadPDF() {
      html2canvas(document.querySelector('.report-body'), {
        useCORS: true,
      }).then(canvas => {
        const imgData = canvas.toDataURL('image/jpeg')
        const doc = new jsPDF('p', 'pt', [canvas.height, 850])
        doc.addImage(imgData, 'jpeg', -15, 0, canvas.width, canvas.height)
        doc.save('report.pdf')
      })
    }

你可能感兴趣的:(html转PDF进行下载)