Becky Becky -4 years ago 125
HTML Question

Getting error while using jsPdf Autotable

Am trying to print the Data into the PDF so i used jsPdf , at that time the data's are not aligned properly into my PDF table . So i searched in many site's they referred me to use jsPdf Auto-table . Here the problem arises , before the injection of jsPdf Auto-table every thing is working fine(without alignment) but after i insert

<script src=""></script>

this into my index.html am getting error,

Uncaught ReferenceError: jsPDF is not defined (jspdf.plugin.autotable.js:10)

Answer Source

You need to include the jspdf library before the jspdf-autotable plugin. See the docs for further information. You might also want to use the latest version 2.0.28.

<script src=""></script>

<!-- EDIT: For now, add this line between the libraries -->
<!-- The reason being that jspdf includes a version of requirejs which -->
<!-- jspdf-autotable currently is not expecting. You can also use version < 2.0.21 -->
<script>if (window.define) delete window.define.amd;</script>

<script src=""></script>

var columns = ["ID", "Name", "Country"];
var rows = [
   [1, "Shaw", "Tanzania"],
   [2, "Nelson", "Kazakhstan"],
   [3, "Garcia", "Madagascar"]
var doc = new jsPDF('p', 'pt');
doc.autoTable(columns, rows);'table.pdf');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download