我有一个问题在这里,我有一个JS Highcharts,图像,表格等html报告页面,我正在寻找导出到PDF报告的一切(与表格,图像等)。问题是,因为Highcharts (和其他JS图表)是在浏览器中呈现的,所以它不会出现在生成的pdf中。我试过JSPdf和PhantomJS,但是有了这些“屏幕截图”生成器,我失去了我用xhtml2pdf创建的所有样式和格式(封面和封底页,水印等)。你能帮我一下吗?
发布于 2020-11-27 08:46:53
我已经解决了!。-有与HighchartsJS图形的模板。.-读取每个图表画布,并将其存储在自己的隐藏输入中:
(function (H) {
H.Chart.prototype.createCanvas = function (divId) {
var svg = this.getSVG(),
width = parseInt(svg.match(/width="([0-9]+)"/)[1]),
height = parseInt(svg.match(/height="([0-9]+)"/)[1]),
canvas = document.createElement('canvas');
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
if (canvas.getContext && canvas.getContext('2d')) {
canvg(canvas, svg);
return canvas.toDataURL("image/jpeg");
}
else {
alert("Your browser doesn't support this feature, please use a modern browser");
return false;
}
}
}(Highcharts));
var imageData = $("#ausentismo_tot").highcharts().createCanvas();
$('#aus_tot_image').val(imageData); //Hidden Input.-带着发布的信息旅行并在views.py中处理它:
aus_tot_image = request.POST['aus_tot_image'].-使用xhtml2pdf的“render_to_pdf_response”打印pdf文件:
<img src="{{ aus_inc_image }}" >https://stackoverflow.com/questions/65011986
复制相似问题