Dipu Kumar
Dipu Kumar

Reputation: 45

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>

Upvotes: 0

Views: 8462

Answers (1)

Simon Bengtsson
Simon Bengtsson

Reputation: 8151

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>

Upvotes: 2

Related Questions