I have a html page containing many text in tables. I'm using jspdf version 1.5 and higher and html2canvas libraries for creating a pdf when clicking on a button "generate the pdf".
The pdf is correctly generated.
Here is my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Template 01</title>
<link id="BootstrapCSS" rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body id="toPDF">
<div id="result">
<div id="target">
<div class="container-fluid">
<p id="generateButton" style="display: none;"><button type="button" class="btn btn-primary btn-lg" onclick="download()">Generate PDF</button></p>
<div id="content">
<table id="table01" class="table table-bordered table_border">
...
</table>
<table id="table02" class="table table-bordered table_border">
...
</table>
...
</div>
</div>
</div>
</div>
</body>
<script src="jspdf.umd.js"></script>
<script src="jquery-2.1.4.min.js"></script>
<script src="html2canvas.min.js"></script>
<script>
function download() {
let pdf = new jspdf.jsPDF('p', 'pt', 'a4')
let srcwidth = document.getElementById('toPDF').scrollWidth;
pdf.html(document.getElementById('toPDF'), {
html2canvas: {
scale: 595.26 / srcwidth, //595.26 is the width of A4
scrollY: 0
},
filename: 'jspdf',
x: 0,
y: 0,
callback: function () {
window.open(pdf.output('bloburl'));
}
});
}
</script>
</html>
And the jsfiddle code: http://jsfiddle.net/amadese57/17npbu4y
My problem is the tables are sometimes broken at the bottom of the page (and at the top of the next page). I would like to create automatically a break when the tables cannot be entirely on the page.
I don't know how to do that and if I can do that in the function pdf.html() that I used.
Could you help me please with that ?
Thanks in advance for your help