0

I have some code in html2canvas. In that code which jquery are suitable I try to make html2canvas.js file insert a comment but the $ symbol is not defined is indicated. In notepad no output result. How do I get get result for download the pdf&png image ?

$(document).ready(function() {

  var element = $("#html-content-holder"); // global variable
  var getCanvas; // global variable
  html2canvas(element, {
    onrendered: function(canvas) {

      getCanvas = canvas;
    }
  });
  var specialElementHandlers = {
    '#editor': function(element, renderer) {
      return true;
    }
  };
  $("#cmd").on('click', function() {
    var imgageData = getCanvas.toDataURL("image/png");
    // Now browser starts downloading it instead of just showing it
    var newData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream");
    $("#cmd").attr("download", "Sample_Pic.png").attr("href", newData);
    var doc = new jsPDF();
    doc.fromHTML($('#target').html(), 15, 15, {
      'width': 170,
      'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
  });


});
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="shot.js"></script>

<script type="text/javascript" src="html2canvas.js"></script>




<link rel="stylesheet" type="text/css" href="shot.css">

</head>
<body>
  <div id="html-content-holder" style="background-color: #FFFFFF; width: 500px;
        padding-left: 25px; padding-top: 10px;">
    <div id="target">
      <div id="content">
        <h3>Hello, this is mathit app</h3>
        <a class="upload">Upload to Formulas</a>
        <h2>
                        This is <b>10th Std Notes</b> <span style="color: red"></span>
                    </h2>
        <p>Study about The polynomial of degree two is called quadratic polynomial and equation corresponding to a quadratic polynomial P(x) is called a quadratic equation in variable x. Thus, P(x) = ax2 + bx + c =0, R is known as the standard form of quadratic
          equation. There are two types of quadratic equation. (i) Complete quadratic equation : The equation ax2 + bx + c =0 where a,b,c is not equal to 0. (ii) Pure quadratic equation : An equation in the form of ax2 = 0, a is not equal to 0, b,c is
          equal to 0.</p>

      </div>
    </div>
  </div>

  <a id="cmd" href="#" class="button">generate PDF</a>
  <br/>
  
</body>
</html>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Prasanth Klr
  • 131
  • 1
  • 2
  • 9

1 Answers1

0

The $ symbol is not defined since you forgot to include the jQuery library. Include the library in the head tag.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

Here is a link to a list of their CDNs.

DVJex
  • 314
  • 4
  • 13