我有来自表格的大量数据,我在表格中显示数据,当我想将故事转换成pdf时,我按照以下方式进行了
$("#btnPdf").click(function(){
var dt = new Date();
var day = dt.getDate();
var month = dt.getMonth() + 1;
var year = dt.getFullYear();
var hour = dt.getHours();
var mins = dt.getMinutes();
var postfix = month + "-" + day + "-" + year + "_" + hour + ":" + mins;
var docs = 'ltr_'+ postfix;
var w = 1000;
var h = 1000;
var div = document.querySelector('#divtoconvert');
var canvas = document.createElement('canvas');
canvas.width = w*2;
canvas.height = h*2;
canvas.style.width = w + 'px';
canvas.style.height = h + 'px';
var context = canvas.getContext('2d');
context.scale(2,2);
var count = document.getElementById('count').value;
var doc = new jsPDF('p', 'mm', "a4");
doc.deletePage(1);
for(var j=1;j<=count;j++)
{
html2canvas(document.getElementById("tbl-data"+j), {
useCORS: true,
allowTaint: true,
letterRendering: true,
scale: 2,
canvas: canvas,
onrendered: function(canvas) {
var width = canvas.width;
var height = canvas.height;
var millimeters = {};
millimeters.width = Math.floor(width * 0.264583);
millimeters.height = Math.floor(height * 0.264583);
var imgData = canvas.toDataURL('image/png',1.0);
doc.addPage(millimeters.width, millimeters.height);
doc.addImage(imgData, 'png',0,0);
},
});
}
setTimeout(function() {
//jsPDF code to save file
doc.save(docs+'.pdf');
}, 2000);
});
我已经在循环中检索了数据,并且我已经在html中将每一行显示为表格,并且所有这些都适用于数据库中的低数据。但是我在数据库中有115行,为此pdf显示为空,不知道它为什么会发生? 此处count等于115行和&lt; tbl-data&#39;是每个表的id。 请提前告知我正确的道路。