JSFiddle - React, Tailwind, and code Playground

HTML

<div id="hello">
  <p>Hello</p>
  <canvas id="myCanvas"></canvas>
</div>

JavaScript

var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText("Hello World", 10, 50);



setTimeout(function() {
  var restorepage = $('body').html();
  var printcontent = $("#hello").clone();
  $('body').empty().html(printcontent);
  window.print();
  $('body').html(restorepage);
}, 1000);