After importing the jsPDF library, I attempted to export to PDF but encountered a JavaScript error stating that jsPDF is not defined.
I tried various solutions from similar posts but none of them seemed to work for me.
You can find the fiddle here: https://jsfiddle.net/aybhvf8e/1/
<script type="text/javascript" src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script>
$( document ).ready(function() {
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
})
$('#cmd').click(function () {
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
<div id="content">
<h3>Hello, this is a H3 tag</h3>
<p>A paragraph</p>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>