Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!