我现在的情况是需要使用 jspdf 将图表输出到 javascript 生成的 pdf 文档中。
我想转换我网站上显示的图表。
我为此使用 Chartist。
有什么办法可以做到这一点吗?
最佳答案
您可以查看 jsPDF 的 addHTML 函数,它应该为您提供 Canvas 的干净副本
const pdf = new jsPDF('p','pt','a4')
const chartistChart = document.getElementById('your-chartist-chart')
const previewPane = document.getElementById('preview-pane')
// addHTML is marked as deprecated, see links below for further information
pdf.addHTML(chartistChart, function() {
// Get the output pdf data URI
const outputString = pdf.output('datauristring')
// Changes the src to new data URI
previewPane.attr('src', outputString)
})
关于javascript - 将 Chartist 图表导出为 pdf 文档 (jspdf),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31425244/