【发布时间】:2020-09-08 02:50:21
【问题描述】:
我导入了 jsPDF 库并尝试导出为 PDF,但我收到 JavaScript 错误 jsPDF 未定义。
我尝试了其他类似的帖子,但它对我不起作用。
我在这里得到了小提琴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>
【问题讨论】:
标签: javascript jspdf