Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
html2Canvas - Error finding the DIV - React Production Build

I am having a super strange error occur when using html2Canvas to print a PDF. Once the function is called, it immediately throws an error:

"807ms html2canvas: Error finding the DIV in the cloned document"

Upon calling the function again, immediately after, everything works as expected. This is ONLY occurring in the Production Build of react, making this issue difficult to debug.

Function in question:

async generateAllPdf(PDFStructure) {

        this.setState({
            generatingPDF: true
        })

        const doc = new jsPDF('p', 'mm', 'letter', true);
       
        let ids = [];
        for (let k = 0; k < PDFStructure.length; k++) {
            ids.push(PDFStructure[k].ref);
        }


        const length = PDFStructure.length;
        for (let i = 0; i < length; i++) {
            let percent = Math.floor((i / length)*100) + '%'
            this.handleProgress(percent)
            const chart = document.getElementById(ids[i]);
            // excute this function then exit loop
            await html2Canvas(chart, { scale: 3, useCORS: true }).then((canvas) => {
                const imgData = canvas.toDataURL('image/jpeg',0.5);
                //doc.addImage(canvas.toDataURL('image/jpeg'), 'JPEG', 10, 50, 200, 150);
                doc.addImage(imgData, 'JPEG', 0, 22.6, 216, 279.4, undefined, 'FAST');
                if (i < (length - 1)) {
                    doc.addPage();
                }
            });
        }

        this.setState({
            generatingPDF: false
        })

        doc.save("MCX-" + Moment().format('YYYY-MM-DD') + ".pdf");
    }
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda