我正在尝试使用jSPDf和Html2Canvas.js从HTML生成PDF,该代码在Chrome中工作正常,但是在IE中,它第一次可以正常工作,而在生成PDF时,第二次控件重叠并对齐到了一侧PDF。
请提供在第二次提交点击时生成正确图像的解决方案
function generateCanvas() {
pdf = new jsPDF("p", "pt", "a4");
html2canvas($('#div1')[0], {
onrendered: function(canvas) {
var contentWidth = canvas.width;
var contentHeight = canvas.height;
var pageHeight = contentWidth / 592.28 * 841.89;
var leftHeight = contentHeight;
var position = 0;
var imgWidth = 595.28;
var imgHeight = 592.28 / contentWidth * contentHeight;
var pageData = canvas.toDataURL('image/png');
console.log(pageData)
if (leftHeight < pageHeight) {
pdf.addImage(pageData, 'PNG', 0, 0, 700, 900);
} else {
while (leftHeight > 0) {
pdf.addImage(pageData, 'PNG', 0, position, imgWidth, imgHeight)
leftHeight -= pageHeight;
position -= 841.89;
if (leftHeight > 0) {
pdf.addPage();
}
}
}
pdf.save('Test.pdf');
}
});
}