Reputation: 1
So i'm running this code to print sections on a page using jsPDF but he keeps returning
TypeError: doc.fromHTML is not a function
function printPDF(object){
var section_id = jQuery(object).parent().find('p').text().substr(0,3).replace('.','_');
if(!jQuery('#contentsection'+section_id).length){
jQuery(object).parent().parent().parent().before('<div id="contentsection'+section_id+'">'+'</div>');
}
var title_block = jQuery(object).parent().parent().parent();
var text_under_title = jQuery(object).parent().parent().parent().next();
jQuery('#contentsection'+section_id).append(title_block);
jQuery('#contentsection'+section_id).append(text_under_title);
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
jQuery('.print-to-pdf').click(function () {
doc.fromHTML(jQuery('#contentsection'+section_id).html(), 15, 15, {
'width': 170,
// 'elementHandlers': specialElementHandlers
});
doc.save('test-file.pdf');
});
}
Someone that knows what happens or knows what i'm doing wrong, i dont know what these 'elementHandlers' are too.
Upvotes: 0
Views: 10064
Reputation: 366
It happens when you import jspdf.js instead of jspdf.debug.js. The latter doesn't have the fromHTML() function so it throws error.
Include proper libraries.
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script>
Make sure jspdf.js is not present in references.
Upvotes: 0