Trying to understand the HTML2Canvas API has been quite challenging due to the limited documentation available. My goal is to place multiple div elements, each representing a different page, into a single PDF file. It might sound simple at first, but in reality, it's much more complex. I've experimented with various approaches to achieve this, only to discover that the asynchronous nature of JavaScript adds another layer of difficulty.
This is what I currently have:
html2canvas($("#monthly_agg_report_container"), {
onrendered: function(canvas) {
var doc = new jsPDF('landscape', 'pt','a2');
var imgData = canvas.toDataURL("image/png");
doc.addImage(imgData,'PNG',0,0,canvas.width*1.33,canvas.height*1.33);
doc.save('report.pdf');
}
}).then(function(){
// Another html2canvas attempt didn't work properly, resulting in an empty page in the PDF.
alert('done');
})