react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

save the chart in PDF usinig Jspdf

Open mahermagdy opened this issue 9 years ago • 9 comments

@jerairrest Hi I need to save the chart in PDf file using JsPDF like the example below using JsPDF and chartJS Example:- https://fiddle.jshell.net/kL68ey5z/94/

so I need the steps or the solution to extract the chart in PDF( as the image) .

mahermagdy avatar Jul 24 '17 14:07 mahermagdy

@DocX @octalmage @mosanger @nrdobie @soska @ Hi Guys Anyone can help me

mahermagdy avatar Jul 25 '17 10:07 mahermagdy

I need the same solution.

lucasapereira avatar Aug 11 '17 14:08 lucasapereira

No clue. This is just a wrapper for ChartJS, so I would check with them!

octalmage avatar Aug 11 '17 19:08 octalmage

https://fiddle.jshell.net/kL68ey5z/105/

octalmage avatar Aug 11 '17 20:08 octalmage

Thanks @octalmage .

Closing

jerairrest avatar Sep 25 '17 00:09 jerairrest

Solution link is broken, can someone post the solution to this issue?

Tommy92708 avatar Sep 08 '18 03:09 Tommy92708

Solution link is still broken. Could someone post the solution again? Would appreciate that 👍

alvinjulian avatar Feb 21 '19 06:02 alvinjulian

+1 i also need this solution

nakedfool avatar Sep 17 '19 11:09 nakedfool

import PdfConverter from 'jspdf';
import DomToImage from 'dom-to-image';

const convertToPdf = () => {
    const canvas= document.querySelector('.canvas')[0];
    const imgWidth = 190;
    const pdf = new PdfConverter('p', 'mm');
    DomToImage.toPng(canvas).then(dataURL => {
           const imgHeight = (canvas.clientHeight * imgWidth) / canvas.clientWidth;
           pdf.addImage(dataURL, 'PNG', 10, 20, imgWidth, imgHeight);
     });
     pdf.save('save.pdf');
};

arfath77 avatar Jun 30 '21 08:06 arfath77