Export multiple charts and tables into 1 PDF

∥☆過路亽.° 提交于 2019-12-25 07:47:45

问题


I'm looking for 2 JS libraries for generating charts and PDFs. I've already tested some, but none of them has satisfied my needs so far.

Background:

I need to create several independent charts and tables in order to export all of them afterwards into 1 PDF.

What I already tried:

I have already tested highcharts and amcharts, but they don't seem to work the way I need them.

highcharts offers the possibility to create a chart and a table, showing the same data. So same input visualized differently.
Nobody could help me here.

With amcharts I could export multiple charts, but the problem with the tables remained the same: They only can display the same content in different ways.
Nobody could help me here.

Both libraries provide an own export function. However, when creating a custom HTML table (<table><tr>...), I need to use an extern PDF library, in my case it was jspdf. That way I can export my custom tables, but the charts won't be exported properly anymore.
Here is a fiddle.

Question:

Does anybody know a way or another library, so that I can properly export multiple charts and tables into 1 PDF?


回答1:


Edit: sorry they are using SVG not canvas. So maybe you can find a way how to convert svg to an image.

I think the problem is that jspdf cannot handle html-canvas proberly. You could try to convert the canvas to an image with html2canvas and feed it to jspdf.

Have a look here: Html5-canvas to pdf

Copied from the answer:

html2canvas($("#canvas"), {
    onrendered: function(canvas) {         
        var imgData = canvas.toDataURL(
            'image/png');              
        var doc = new jsPDF('p', 'mm');
        doc.addImage(imgData, 'PNG', 10, 10);
        doc.save('sample-file.pdf');
    }
});


来源:https://stackoverflow.com/questions/41891575/export-multiple-charts-and-tables-into-1-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!