i created a canvas using javascript and appended it to an output div, i want to take that canvas and download it as a png on client side but i could not find a way to do it
i tried even canva2image but i could not make it work
heres my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="html2canvas.js"></script>
</head>
<body>
<div id="tabela"><p>this is a test</p></div>
<button onclick="takeshot()">Copy</button>
<div id="output"></div>
<script type="text/javascript">
// Define the function
// to screenshot the div
function takeshot() {
let div = document.getElementById('tabela');
html2canvas(div).then(
function(canvas) {
document
.getElementById('output')
.appendChild(canvas);
})
}
</script>
</body>
</html>
2
Answers
You can use this js file.
https://html2canvas.hertzen.com/dist/html2canvas.min.js
I add sample code below.
You can test this.