Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ChartJS and jsPDF - why the background is black?

I am generating PDF file using jsPDF library. Everything is okay, but at page my chart has white background ( on PDF - black ):

Chart from my webpage: enter image description here

And from PDF: enter image description here

my code for generating file:

var newCanvas = document.querySelector('#canvasChart');
    var newCanvasImg = newCanvas.toDataURL("image/jpeg", 1.0);
    var doc = new jsPDF('landscape');
    doc.setFontSize(20);
    doc.text(15, 15, "Super Cool Chart");
    doc.addImage(newCanvasImg, 'JPEG', 10, 10, 280, 150 );
    doc.save('new-canvas.pdf');

Do you have an idea how to solve this ? Thanks in advance,

like image 372
python_beg2 Avatar asked Aug 15 '17 08:08

python_beg2


1 Answers

Maybe later, but I solved using PNG image:

var newCanvasImg = newCanvas.toDataURL("image/png", 1.0);

Hope this helps.

like image 125
Massimo Simonini Avatar answered Oct 14 '22 08:10

Massimo Simonini