我正在使用dc.js来创建图表。我想将图表导出为pdf。似乎转换为SVG然后使用perl脚本将SVG转换为pdf是唯一的方法。有什么建议吗?
答案 0 :(得分:0)
我使用Inkscape(在服务器上)使用此方法:
JS:
// --- create your chart before this ---
postdata = {
'url':CryptoJS.MD5(window.location.href).toString(),
//used to name the file based on its url (used for caching, containing parameters in my case)
'svg':$('#chart').html()
//the created svg chart (using jQuery here)
};
$.post('create_pdf.php',postdata);
//POST the svg to php (using jQuery here)
create_pdf.php:
//save the svg file as XYZ.svg
file_put_contents($_POST['url'] . '.svg',$_POST['svg']);
// run the command: inkscape -z XYZ.svg -A XYZ.pdf
// for png would do: inkscape -z XYZ.svg -e XYZ.png
$com = 'inkscape -z ' . $_POST['url'] . '.svg -A ' . $_POST['url'] . '.pdf';
exec($com);
注意:我直接使用d3.js,而不是dc.js(不确定)