2

I would like to use html2canvas but it is not clear enough how to use it in the documentation. What libraries I should include ? and then is this peace of code just what I need ? What about the proxy ? and How I could save the screen shot after it's taken ?

$('body').html2canvas();
var queue = html2canvas.Parse();
var canvas = html2canvas.Renderer(queue,{elements:{length:1}});
var img = canvas.toDataURL()
window.open(img);
Noon
  • 1,181
  • 6
  • 20
  • 38

3 Answers3

3

For me, it was working this way:

$('#map').html2canvas({
onrendered: function( canvas ) {
  var img = canvas.toDataURL()
  window.open(img);
}
Niklas Hoesl
  • 320
  • 3
  • 8
0

The current latest version works this way:

html2canvas($('#map'),
 {
  onrendered: function(canvas) {
    cvs = canvas.toDataURL('image/png');
    window.open(cvs)
 }
});
roxxypoxxy
  • 2,973
  • 1
  • 21
  • 28
0

Here's a minimal, complete example that shows how to convert the DOM to canvas with html2canvas, convert the canvas to base64, and finally trigger a download.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
  <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
</head>
<body>
  <h1>Hello World</h1>
<script>
(async () => {
  const canvas = await html2canvas(document.body);
  const base64 = canvas.toDataURL();
  const a = document.createElement("a");
  a.href = base64;
  a.download = "html2canvas-test.png";
  a.click();
})();
</script>
</body>
</html>

I'm not sure what you mean about a proxy.

ggorlen
  • 44,755
  • 7
  • 76
  • 106