Generate PDF from HTML using JQuery and jsPDF

Here is the code to generate PDF from HTML using jQuery and jspdf.There are no events occurs when the "download pdf" button clicks. jquery:

$(document).ready(function() < $('#download_pdf').click(function(e) < e.preventDefault(); var pdf = new jsPDF('p', 'pt', 'letter'), source = $('#table_stock')[0], specialElementHandlers = < '#table_stock': function(element, renderer) < return true >> margins = < top: 60, bottom: 60, left: 40, width: 522 >; pdf.fromHTML( source, margins.left, margins.top, < 'width': margins.width, 'elementHandlers': specialElementHandlers >, function(dispose) < pdf.save('Stockreport.pdf'); >, margins ) >); >);
 
user10662159 asked Jul 19, 2018 at 9:53 377 1 1 gold badge 8 8 silver badges 32 32 bronze badges any error message ? Commented Jul 19, 2018 at 9:59 You're passing null as source, due to $('#table_stock')[0] doesn't seems to exists in your HTML. Commented Jul 19, 2018 at 10:06 Uncaught TypeError: Cannot read property '1' of undefined @Natsathorn Commented Jul 19, 2018 at 10:09 there is no '1' in here. but let check where is it in your code Commented Jul 19, 2018 at 10:11 include this library mrrio.github.io/jspdf.js Commented Jul 19, 2018 at 10:23

1 Answer 1

You have not included the lib include the lib as following because after adding this lib there is no error.

Another thing just use $('#table_stock') there is no requirment of [0] , if you are using class selector then $('.stock_report')[0] .