0

I am using html2canvas.js to make screenshot from html and jspdf.js to make pdf. My html is like below

<div id="panel-item-all-annotations">
   <div class="panel-body" id="" style="width: 100%;">
         {{--some html with image--}}
   </div>
</div>
<canvas width="800" height="500" style="display: block;"></canvas>

I am using the canvas to place the image of div#panel-item-all-annotations by the JS code like below

html2canvas(document.querySelector("#panel-item-all-annotations"), {canvas: canvas}).then(function(canvas) {
        console.log('Drew on the existing canvas');
});

But it is not placing image properly on the canvas. It is placing it at very bottom and right of the canvas like below Improper image place on canvas

html2canvas.js url: https://html2canvas.hertzen.com/ jspdf: https://github.com/MrRio/jsPDF

Mithu A Quayium
  • 729
  • 5
  • 14

1 Answers1

0

I'm not sure why it's doing that to you. There must be something else going on. Stripping it down to super-simple stuff seems to work. There's an example here:

https://lab-keqpanlmmw.now.sh

Here is the code but it won't run here on StackOverflow.

function go() {
  let input = document.querySelector("#input");
  let output = document.querySelector("#output");
  html2canvas(input, {
    canvas: output
  });
}
#input {
  background-color: orange;
  color: white;
  padding: 1em;
  font-family: sans-serif;
  max-width: 200px;
}

#output {
  border: 1px solid black;
  width: 300px;
  height: 200px;
  margin-top: 1em;
}
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<div id="input">
  {{--some html with image--}}
</div>
<div>
  <button onclick="go()">Go</button>
</div>
<div>
  <canvas id="output"></canvas>
</div>
Will
  • 3,201
  • 1
  • 19
  • 17