0
votes

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>
1
The question is too generic to answer. Please also provide information about any errors received and the value of the variables res and elem. - Simon Bengtsson
Uncaught TypeError: Cannot read property 'API' of undefined at Object.<anonymous> (jspdf.plugin.autotable.js:2267) at webpack_require (jspdf.plugin.autotable.js:39) at exports.__esModule (jspdf.plugin.autotable.js:85) at jspdf.plugin.autotable.js:88 at webpackUniversalModuleDefinition (jspdf.plugin.autotable.js:16) at jspdf.plugin.autotable.js:19 - Dipu Kumar
Uncaught ReferenceError: jsPDF is not defined - Dipu Kumar

1 Answers

2
votes

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>