8

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,

python_beg2
  • 299
  • 4
  • 13
  • 2
    [Chart.js: Canvas background color #2830](https://github.com/chartjs/Chart.js/issues/2830) – Andreas Aug 15 '17 at 08:52
  • 2
    Possible duplicate of [How to save Chart JS charts as image without black background using blobs and filesaver?](https://stackoverflow.com/questions/43664722/how-to-save-chart-js-charts-as-image-without-black-background-using-blobs-and-fi) – Andreas Aug 15 '17 at 08:55
  • An Article from github helped a lot! thank you – python_beg2 Aug 15 '17 at 09:01

1 Answers1

14

Maybe later, but I solved using PNG image:

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

Hope this helps.