Export HTML table to PDF, WORD, PNG using TableExport.js

Aman Taneja picture Aman Taneja · Mar 1, 2015 · Viewed 13.6k times · Source

I am trying to export a Table via PDF using the js provided by Ngiriraj Table Export Demo. The code is:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
    <script type="text/javascript" src="./js/tableExport.js"></script>
    <script type="text/javascript" src="js/jquery.base64.js"></script>
    <script type="text/javascript" src="js/sprintf.js"></script>
    <script type="text/javascript" src="js/jspdf.js"></script>
    <script type="text/javascript" src="js/base64.js"></script>
    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/jquery.mobile-1.4.2.min.js"></script>

<title>Insert title here</title>
</head>
<body>


<button id="export" style="height: auto; width: auto;" onClick="$('#tableID').tableExport({type:'pdf',escape:'false'});">Click Here for PDF!</button>


<table id="tableID">
<tr>
<td>ABC</td>
<td>BDE</td>
</tr>
</table>
</body>
</html>

However, when I click on the button, nothing happens. Console shows a error UNCAUGHT TYPE ERROR whenever the button is clicked.

Answer

Jonathan picture Jonathan · Mar 1, 2015

Include any scripts reliant on jQuery after the jQuery. I'd say best practice is to put jQuery first. Let me know if this works:

<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.mobile-1.4.2.min.js"></script>
<script type="text/javascript" src="./js/tableExport.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/sprintf.js"></script>
<script type="text/javascript" src="js/jspdf.js"></script>
<script type="text/javascript" src="js/base64.js"></script>