使用jspdf-autotable

时间:2017-10-01 18:07:19

标签: javascript pdf jspdf-autotable

我正在使用jspdf-autotable下载pdf文件。我的html文件的表id是myTable。我没有得到pdf文件作为table.pdf.What shoule我改变了我的代码?我的代码在javascript下面

<script language="text/javascript">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/2.3.2/jspdf.plugin.autotable.js"></script>
    <script>
    var doc = new jsPDF('p', 'pt');
    var elem = document.getElementById("myTable");
    var res = doc.autoTableHtmlToJson(elem);
    doc.autoTable(res.columns, res.data);
    doc.save("table.pdf"); </script>

</script>

1 个答案:

答案 0 :(得分:2)

您不能将脚本标记放在脚本标记中。将代码更改为:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/2.3.2/jspdf.plugin.autotable.js"></script>
<script>
    var doc = new jsPDF('p', 'pt');
    var elem = document.getElementById("myTable");
    var res = doc.autoTableHtmlToJson(elem);
    doc.autoTable(res.columns, res.data);
    doc.save("table.pdf");
</script>