dom-to-image icon indicating copy to clipboard operation
dom-to-image copied to clipboard

Div scroll issue

Open piyushSinghalDemo opened this issue 7 years ago • 10 comments

Use case:

If we have much data in a div and i am trying to get small complete image of that content, that time it is giving me scroll in image and only visible part of that div is reflecting in image

[jsfiddle]([https://jsfiddle.net/singhalpiyush1993/2m8dcr63/26/]) https://jsfiddle.net/singhalpiyush1993/2m8dcr63/26/

Expected behavior

i should get complete content in image

Actual behavior (stack traces, console logs etc)

getting only visible part of that saction

piyushSinghalDemo avatar Feb 01 '18 12:02 piyushSinghalDemo

+1 i Have this problem, and waiting a correct ansver for this.

Mahmuduman avatar Feb 01 '18 16:02 Mahmuduman

Hi Guys, Is there any idea i can try to resolve this issue?

piyushSinghalDemo avatar Feb 05 '18 07:02 piyushSinghalDemo

You fix This Problem with div inside div method,

Up level div overflow scroll and have width and heighth, inside div width and height auto

when you try render, select inside div, then it get real width and heigth of element without scroll capture..

sample.

style.css

#upsideDiv{ width:300px; heighth:300px; overflow:scroll; } #insideDiv{ width:auto; heighth:auto; }

js Code------------------------------------------------------------------------- var node = document.getElementById('insideDiv');
domtoimage.toPng(node) .then(function (dataUrl) { document.getElementById("showImage").src =dataUrl; }) .catch(function (error) { console.error('errorr"); });

@piyushSinghalDemo

Mahmuduman avatar Feb 22 '18 10:02 Mahmuduman

Finally; https://jsfiddle.net/2m8dcr63/32/

Mahmuduman avatar Feb 22 '18 10:02 Mahmuduman

In the last version of the library, it is no need to add width: auto; height: auto

Passing the scroll height and width options should be enough: domtoimage.toPng(node, { width: node.scrollWidth, height: node.scrollHeight })

See a working example here: https://jsfiddle.net/najorcruzcruz/kL9us4x1/6/

najor avatar Mar 01 '19 09:03 najor

what if we have a scrollable-div inside a parent-div and we are converting dom for parent-div then how will we get the visible tags in scrollable-div ?

Sugam-intelligaia avatar Apr 17 '19 15:04 Sugam-intelligaia

what if we have a scrollable-div inside a parent-div and we are converting dom for parent-div then how will we get the visible tags in scrollable-div?

You need to get scrollable-div to convert image not the parent div.

sryara avatar Jun 18 '19 20:06 sryara

In the last version of the library, it is no need to add width: auto; height: auto

Passing the scroll height and width options should be enough: domtoimage.toPng(node, { width: node.scrollWidth, height: node.scrollHeight })

See a working example here: https://jsfiddle.net/najorcruzcruz/kL9us4x1/6/

this solves the problem! GREAT!

palminha avatar Apr 23 '20 23:04 palminha

I have also same issue but i am fail to solve this please help me tooo...

My React JS Part

import domtoimage from 'dom-to-image';
import download from 'downloadjs';
// ...
const downloadSS = () =>{
        
        var today = new Date();
        var date = today.getFullYear()+''+(today.getMonth()+1)+''+today.getDate();
        var time = today.getHours()+''+today.getMinutes()+''+today.getSeconds();
        var dateTime = date+'_'+time;
        let ssPart = document.getElementsByClassName('ToDo')
        domtoimage.toPng(ssPart[0])
        .then(function (image) {
            download(image, `Web-TodoOf-${dateTime}.png`);
        });
    }
//...
<div className="ToDo">
 <h2><FaClipboardCheck/> I have Todo:</h2>
                        <ul>
                            {todos.map((todo,index)=>(
                                <li id={todo.id}>
                                    { todo.complete ? 
                                        <div className="TodoListPartComplete">
                                            <p>{todo.data}</p>
                                            <p className="deleteAlign">
                                                <button className="deleteAlignbtn" onClick={()=>deleteTodo(index)}>
                                                    <MdDeleteForever size={20}/>
                                                </button>
                                            </p>
                                            <p>
                                                <button className="TaskCompletebtn" onClick={()=>taskComplete(index,todo.complete,todo.data)}>
                                                    <GoChecklist size={20}/>
                                                </button>
                                            </p>
                                        </div>

My Css Part

.ToDo{
    top:90px;
    right: 5px;
    left: 5px;
    bottom: 94px;

    position:fixed;
    overflow-y: scroll;

    border-radius: 10px;
    border: 2px solid rgb(165, 107, 32);
    background-color: rgb(255, 255, 255);
}

Sukarnascience avatar Jun 28 '21 17:06 Sukarnascience

I am also facing similar issue. When I try to capture the list of options and after scrolling to the bottom, the screenshot unable to detect the scrolled part. Instead it has been capturing from the top of the list. Please find the attached image, in which the scrrenshot gets appended to the same page after capturing. In my case I should capture the entire screen. And it is not enough if I consider select options div alone for screen capture. Can someone help me to capture the image correctly? image

lokeshsasapu avatar Jun 01 '22 09:06 lokeshsasapu