Page load error when exporting a PDF file using html2canvas and jsPdf

0

Good afternoon I'm developing a system that creates one or more templates in HTML and exports them to PDF for the creation of posters.

It takes the html area for each poster, converts it to the image with the html2canvas, and then adds it to a PDF page with the jsPdf plugin. At the end a single PDF file with X pages should be generated according to the number of posters.

The problem is that when I try to export sheets in size A1 (which are quite large) it ends up giving this image error below. This problem only happens when I try to export more than 5 sheets. I already tested in another micro where he also presented the same problem, however he accepted more sheets (9 in total).

One point to note is that 5 sheets are generating a file of about 133 MB and I do not know if there are any limits on account of the plugins or something related.

I really do not have the slightest idea of what could be done in the code to solve this. The first thing I tried was to follow the tips that the browser itself suggested but did not solve. I've researched before but could not find an answer yet. If anyone can at least give a direction on what to search for me to try to solve this already thank you very much.

In case anyone wants to view the code, this is the section that iterates through each HTML template and generates the image.

Note: some variables have already been declared before. I gave preference in showing just this stretch of each.

$.each( $(".folha"), function( key, value) {
                var element = document.getElementsByClassName("folha")[key];
                html2canvas(element, {
                    logging: false,
                    async: false,
                    windowWidth: '100%',
                    windowHeight: '100%',
                    width: folha_width,
                    height: folha_height,
                    useCORS: true}).then(function(canvas) {
                        var data = canvas.toDataURL('image/png', 1);
                        var image = encodeURI(data);
                        count.remove(key);

                        if(count == null || count.length == 0){  
                            doc.addImage(image, 'PNG', 0, 0);
                            var name = 'cartazes-'+cartaz_nomes[folha_nome]+'-'+orientacao+'-com-'+paginas+'-paginas.pdf';
                            doc.save(name); 
                            display_load('none');
                        } else {
                            doc.addImage(image, 'PNG', 0, 0);
                            doc.addPage();
                        }
                });
                paginas +=1;
            });

    
asked by anonymous 18.05.2018 / 22:13

0 answers