I have a problem trying to export an HTML table to PDF with all the canvas it has.
The thing is, i can export the canvas as an image to the PDF but i cant seem to do the same with the tables.
Here is the code:
echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.3/jspdf.min.js"></script>';
echo"<script>
download.addEventListener('click', function () {
var imgData = document.getElementsByTagName('canvas')[0].toDataURL('image/png', 1.0);
var imgData2 = document.getElementsByTagName('canvas')[1].toDataURL('image/png', 1.0);
var imgData_table = document.getElementsByTagName('table')[0].toDataURL('image/png', 1.0);
var pdf = new jsPDF('p', 'px', 'a4');
var i = new Image();
var pageHeight = pdf.internal.pageSize.height;
var pageWidth = pdf.internal.pageSize.width;
console.log(pageHeight + ', ' + pageWidth);
i.src = imgData;
setTimeout(function(){
pdf.addImage(imgData_table, 'png', 0, 0,);
pdf.addPage();
//console.log(i.width + ', ' + i.height);
pdf.addImage(imgData2, 'png', 0, 0,);
pdf.addPage();
pdf.addImage(imgData, 'png', 0,0);
pdf.save('download.pdf');
},600);
}, false);
</script>";
echo "<div class='col-sm-6'>
<button id='download'>download</button>
</div>
";
Does anyone knows what can be done in this case? Thanks!