简体   繁体   English

将多个图表和表格导出为1个PDF

[英]Export multiple charts and tables into 1 PDF

I'm looking for 2 JS libraries for generating charts and PDFs. 我正在寻找2个JS库来生成图表和PDF。 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 . 我需要创建几个独立的图表和表格 ,以便随后将它们全部导出为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. 我已经测试了Highchartsamcharts ,但是它们似乎并没有按照我需要的方式工作。

highcharts offers the possibility to create a chart and a table, showing the same data. highcharts提供了创建图表和表格以显示相同数据的可能性。 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. 使用amcharts可以导出多个图表,但是表格的问题仍然相同:它们只能以不同的方式显示相同的内容。
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 . 但是,在创建自定义HTML表( <table><tr>... )时,我需要使用extern PDF库,在我的情况下是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个PDF

Edit: sorry they are using SVG not canvas. 编辑:对不起,他们使用的是SVG,而不是画布。 So maybe you can find a way how to convert svg to an image. 因此,也许您可​​以找到一种方法来将svg转换为图像。

I think the problem is that jspdf cannot handle html-canvas proberly. 我认为问题在于jspdf无法探究html-canvas。 You could try to convert the canvas to an image with html2canvas and feed it to jspdf. 您可以尝试使用html2canvas将画布转换为图像并将其提供给jspdf。

Have a look here: Html5-canvas to pdf 在这里看看: HTML5-canvas到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');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM