需要引入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')
})
}
网友评论