哪个库和jquery适合这段代码?

时间:2016-08-19 05:47:51

标签: javascript jquery html2canvas

我在html2canvas中有一些代码。在jquery适合的代码中,我尝试使html2canvas.js文件插入注释,但未指定$符号。在记事本中没有输出结果。如何获得下载pdf& png图像的结果?



$(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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

由于您忘记包含jQuery库,因此未定义$符号。 将库包含在head标记中。

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

以下是指向CDNs

列表的链接