I am trying to convert sections of an HTML page to images using JavaScript.
The sections I am trying to convert are in a div tag, and have nested contents.
I want to create a snapshot/screenshot of it, or convert the contents of the div tag into an image (jpeg or png or svng).
My div tag id is “mytest”.
And I have the below section –
However, when I run – the png file downloaded is empty.
html2canvas(document.querySelector("#mytest")).then(canvas => {
const a = document.createElement("a");
a.href = canvas.toDataURL("image/png");
a.download = "image.png";
a.click();
});
To download a PNG file with the contents of the div section