Does anyone have any javascript code that exports a graphics div to a .PDF file?
Does anyone have any javascript code that exports a graphics div to a .PDF file?
After some time researching and breaking my mind about this issue, I was able to create a script using Chart.js to create a simple chart and then I exported this chart to PDF using jsPDF.js , but to be able to pass the chart to the pdf, I would have to do that before make it into a PNG image, to do this task I used the html2canvas plugin. here's the fiddle with the script I used: link
html:
<canvas id="myChart" width="400" height="400"></canvas>
<button type="button">gerar pdf</button>
js:
$('button').on('click', function(){
html2canvas($('#myChart'), {
onrendered: function(canvas) {
var imgData = canvas.toDataURL('image/png');
var pdf = new jsPDF('p', 'mm');
pdf.addImage(imgData, 'PNG', 10, 10);
pdf.save('test.pdf');
}
});
});