I'm coding a pdf generator with html2canvas + jsPDF. I use a recursive method for this. When I launch it on chrome, it make the 'Aw snap!' exception about the 25th iteration. On Mozilla, I can go over 30 and it won't crash. I don't understand why. Here's my code:
function pdfMe(){
var pdf=new jsPDF('l');
var slides=document.getElementById("diapoStock").children; //return some divs
var firstSlide=slides[0].id;
pdfSlide(firstSlide,firstSlide,pdf);
}
//PDF recursive
function pdfSlide(id,idFirst,pdf){
document.getElementById("pdfOutput").innerHTML=""; //empty the output
var next=nextElementOf(id.substr(0,id.length-3)+"Div"); //next div to PDF
showMe(id.substr(0,id.length-3)); //Show the div to PDF in 'central'
html2canvas(document.getElementById("central",{async:true})).then(function (canvas) {
document.getElementById("pdfOutput").appendChild(canvas); //div to PDF shown
var img=canvas.toDataURL("image/png");
pdf.addImage(img, 'PNG', 0, 0, 297, 210); //div added to PDF
if(next===idFirst){ //if end of divs
endPDF(pdf);
}
else{
pdf.addPage();
pdfSlide(next,idFirst,pdf); //to next div
}
});
}
//Print
function endPDF(pdf){
pdf.save('{{ propale.titre }}.pdf');
}
I don't know if it is due to a difference of cache size. I printed it with console.log(window.performance.memory);
but it gave me the same for 10 or 30 iterations.
Is it due to my recursive method? Does it use too much memory?
Hope it's understandable