Here I mentioned some sample code. I'm converting div to image using the dom-to-image library. I'm trying to get the full data of a HTML div element without changing its position. I lose data from the Left and Top of the element. What is the best way to get the whole data of the element without changing the position or suggesting a library for solving this problem?
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js"></script>
<title>Page Title</title>
<style>
#canvas {
height: 200px;
width: 200px;
border: 1px solid;
position: absolute;
top: -100px;
left: -100px
}
</style>
</head>
<body>
<div id="canvas">
<div>This is for testing purpose</div>
</div>
<script>
var canvasId = document.getElementById('canvas');
domtoimage.toJpeg(canvasId, { bgcolor: 'white' }).then(res => {
var link = document.createElement('a');
link.download = 'sample.jpeg';
link.href = res;
link.click();
})
</script>
</body>
</html>