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

249
Visualizações
html2canvas image not showing fully when input-textfield font changes

I am using html2canvas to get the image of an html element(input[type='text']). I have a control which increases the font size of the text field, and also the size of the field to accomodate the text in it.

Before changing the font, html2canvas gets the image of the field and its contents correctly. But when the font size increases, the image is not fully shown again. I have put a red border around the canvas and the gray border is the one around the html element being snapped.

Here is the code that takes the snapshot:

function snapElem(el) {

    function hiddenClone(element){
        // Create clone of element
        let clone = element.cloneNode(true);

        // Position element relatively within the
        // body but still out of the viewport
        let style = clone.style;
        style.position = 'relative';
        style.top = window.innerHeight + 'px';
        style.left = 0;

        // Append clone to body and return the clone
        document.body.appendChild(clone);
        return clone;
    }


// Clone element
    let clone = hiddenClone(el);
    clone.id = "za-clone-id-"+new Date().getTime();


// Use clone with htm2canvas and delete clone
    html2canvas(clone, {
        backgroundColor:null,
        allowTaint: true,
        useCORS: true
    }).then(function (canvas) {
        canvas.style.border  = '2px solid red';
        console.log(canvas.toDataURL());
        canvas.id = "za-real-id-"+new Date().getTime();
        document.body.removeChild(clone);
        document.querySelector(".body-right").appendChild(canvas);
    }).catch((e) => {
        // Handle errors
        console.log(e);
    });
}

Here are the images obtained as the font size of the field changes Images

How can the content remain centered within the canvas when the font size changes.

The page has no scrolling.

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