Depends on what you want to say that the image is distorted.
First, if your container contains external images, you must pass the option useCors : true
to HTML2Canvas. In some cases, if the image is hosted on a server that has a% co_of restrictive%, HTML2Canvas will not be able to load it.
Secondly, if your container contains SVG elements, it is very possible that HTML2Canvas renderee them wrong, because the CSS applied to an SVG is not completely standard and HTML2Canvas tends to distort the thickness of the lines (for example) and the size of the typographies. For those cases, you have to add inline styles to the elements Allow Origin
and text
(in the case of graphics generated with C3).
The following example does work, but I'm not using SVG elements.
html2canvas(document.getElementById('contenido_global'), {
useCORS: true,
onrendered (canvas) {
var link = document.getElementById('download');
var image = canvas.toDataURL();
link.href = image;
link.download = 'screenshot.png';
}
});
#contenido_global {
background:white;
border:2px solid red;
padding:3px;
margin:3px auto;
width:330px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<a id="download">Descargar</a>
<div id="contenido_global">
Hola Soy el contenido global
<br>
<img src="http://1.bp.blogspot.com/-TIPXtgKPnKA/T2wQ1vkrhII/AAAAAAAAGJs/TKfNJT4MIbM/s320/Cat-01.jpg">
</div>