我想把我的html中id ="page2"的其他div转换为图像,并将其添加到同一PDF文件中的另一个页面上,这是我的代码:
<script type="text/javascript" src="jspdf.min.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>
<script type="text/javascript">
function genPDF() {
html2canvas(document.getElementById('hoja1'),{
onrendered: function (canvas) {
var img = canvas.toDataURL("image/png");
var doc= new jsPDF();
doc.addImage(img,'JPEG',0,0,210,230);
doc.save('ContratoMutuo.pdf');
}
});
}
</script>
但只能使用一个div
HTML代码为:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>file</title>
<script type="text/javascript" src="jspdf.min.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>
<script type="text/javascript">
function genPDF() {
html2canvas(document.getElementById('hoja1'),{
onrendered: function (canvas) {
var img = canvas.toDataURL("image/png");
var doc= new jsPDF();
doc.addImage(img,'JPEG',0,0,50,50);
doc.save('test.pdf');
}
});
}
</script>
</head>
<body>
<div id="hoja1">
<TABLE WIDTH=300 HEIGHT=200>
<TD width=100 BGCOLOR="red">prueba </TD>
<TD WIDTH=100 BGCOLOR="yellow">prueba </TD>
<TD WIDTH=100 BGCOLOR="gray">prueba </TD>
</TABLE>
</div>
<div id="hoja2">
<TABLE WIDTH=300 HEIGHT=200>
<TD width=100 BGCOLOR="green">prueba </TD>
<TD WIDTH=100 BGCOLOR="blue">prueba </TD>
<TD WIDTH=100 BGCOLOR="gray">prueba </TD>
</TABLE>
</div>
<a href="javascript: genPDF()">DOWNLOAD PDF</a>
</body>
</html>
2条答案
按热度按时间rn0zuynd1#
如果我正确理解了什么是你试图存档,这可以工作:
dxpyg8gm2#