2

我的情况是我需要使用jspdf将图表输出到 javascript 生成的 pdf 文档中。

我想转换我网站上显示的图表。
我正在为此使用 Chartist。

有没有办法做到这一点?

4

1 回答 1

3

你可以查看 jsPDF 的 addHTML 函数,它应该给你一个干净的画布副本

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)
})
于 2015-07-15T15:29:48.790 回答