我正试着用jsPDF把一个div保存为PDF。这是我的小提琴:https://jsfiddle.net/waleedbinahmed/bfj6qktv/11/,这是别人上传的小提琴:https://jsfiddle.net/waleedbinahmed/8s4qvu27/
第二把小提琴工作得很好。
我试图模仿第二种方法,即包含相同的js和Jquery库。但在我的小提琴上,我得到了这个错误“未捕获ReferenceError:未定义jsPDF”。
我不知道我的小提琴上遗漏了什么,导致了这个问题。请帮助我与需要更新的第二小提琴,以便我可以保存一个div一个PDF。
JS库:https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.debug.js
下面是我的代码: HTML:
<div id="content">
<h3>Hello, this is a H3 tag</h3>
<p>A paragraph</p>
</div>
<div id="editor"></div>
<button onclick="javascript:createPdf()" id="cmd">generate PDF</button>Javascript:
function createPdf() {
var doc = new jsPDF();
source = $('#content')[0];
specialElementHandlers = {
'#editor': function(element, renderer) {
return true
}
};
doc.fromHTML(
source,
15,
15, {
'width': 170,
'elementHandlers': specialElementHandlers
}
);
doc.save('sample-file.pdf')
}谢谢。
发布于 2021-10-13 16:22:33
我看着你的小提琴(第一个不能正常工作),然后粘贴js library from the correct fiddle
而且它起作用了。听起来你导入的库不能工作了。此外,working fiddle还实现了jquery 3.4.1
https://stackoverflow.com/questions/69558848
复制相似问题