简体   繁体   中英

Download pdf file using jspdf-autotable

I am using jspdf-autotable to download pdf file. My table id of html file is myTable. I am not getting pdf file as table.pdf.What shoule I change in my code? My code is below in 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>

You cannot put script tag within script tags. Change the code to:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM