Hi,
I am trying to use a third party library (jsPDF) in my custom widget and I am getting the error
jsPDF is not a constructor
at Object.startup
I am using the code here Edit fiddle - JSFiddle - Code Playground. I would greatly appreciate it if anyone can help me understand why the code is not working.
Javascript
///////////////////////////////////////////////////////////////////////////
define([
'dojo/_base/declare',
'jimu/BaseWidget',
'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.3.1/jspdf.umd.min.js',
//'./widgets/JointUseWidget/libs/jsPDF-master/dist/jspdf.node.min.js',
'jimu/loaderplugins/jquery-loader!https://code.jquery.com/jquery-3.4.1.js,https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.js'
],
function(
declare,
BaseWidget,
jsPDF,
$)
{
return declare([BaseWidget], {
baseClass: 'jimu-widget-Testing_PDF_Stuff',
postCreate: function() {
this.inherited(arguments);
console.log('postCreate');
},
startup: function() {
this.inherited(arguments);
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');
});
},
});
});
HTML
<div>
<div id="content">
<h3>Hello, this is a H3 tag</h3>
<p>a pararaph</p>
</div>
<div id="editor"></div>
<button id="cmd">Generate PDF</button>
</div>