0
votes

I'm developing a web-app on Symfony4 and I need to generate PDF with charts created with Chart.js. For PDFs, I'm using mPDF but it's not able to render such chart... My idea is to create a screenshot of chart generated by chart.js and then pass it as a png to mPDF, but I'm not really sure how to achieve that.

Can you give me a hint if I'm thinking in the right direction?

1

1 Answers

1
votes

Save your Chart.js Canvas in Base64 on chart animation callback, eg:

var canvar_bar = document.createElement("canvas");
new Chart(canvar_bar, {
            type: 'bar',
            data: data,
            options: {  
                    maintainAspectRatio: false,
                    animation:{
                        onComplete: function(){
                            dataURL3 = canvar_bar.toDataURL('image/png');
                        }
                    }
                }
            }));

then use PDFMaker http://pdfmake.org/playground.html to test