Reputation: 21
I'm in a situation were I need to output a chart into a javascript-generated pdf document using jspdf.
I want to convert the charts that are displayed on my website.
I'm using Chartist for this.
Is there any way of doing this?
Upvotes: 2
Views: 3242
Reputation: 4481
you can check out the addHTML function for jsPDF, it should give you a clean copy of the 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)
})
Upvotes: 3