I would use the library: dom-to-image
You can read the documentation on the use her here
Here's an example:
var node = document.getElementById('my-node');
domtoimage.toPng(node)
.then (function (dataUrl) {
var img = new Image();
img.src = dataUrl;
document.body.appendChild(img); //esse método exibe a imagem na própria pagina
})
.catch(function (error) {
console.error('erro exibido caso falhe', error);
});
How do I open the image on another page?
Simple, refer to a blank page as the document value to use.
How do I make the image to be transformed and its download started automatically?
domtoimage.toPng(document.getElementById('my-node'), { quality: 1 })
.then(function (dataUrl) {
var link = document.createElement('a');
link.download = 'NomeDaImagem.png';
link.href = dataUrl;
link.click();
});