我正在使用jsPDF制作我的div容器的PDF
div容器是横向格式的发票
当我点击保存按钮后,警告框中会显示错误。
函数[object Object]出错:saveAs未定义
的javascript:
<script type="text/javascript" src="assets/jsPDF/jspdf.js"></script>
<script type="text/javascript" src="assets/jsPDF/jspdf.plugin.addimage.js"></script>
<script type="text/javascript" src="assets/jsPDF/jspdf.plugin.standard_fonts_metrics.js"></script>
<script type="text/javascript" src="assets/jsPDF/jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="assets/jsPDF/jspdf.plugin.from_html.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var specialElementHandlers = {
'#editor': function (element,renderer) {
return true;
}
};
$('#saveinvoicepdf').click(function () {
var doc = new jsPDF();
doc.fromHTML($('#projectInvoicebox').html(), 15, 15, {
'width': 170,'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
});
</script>
HTML:
<a id="saveinvoicepdf" class="btn btn-two btn-lg" title="Click to print the Invoice">Save as PDF</a>
感谢。
答案 0 :(得分:0)
我遇到了同样的错误并通过添加对jspdf.min.js
的引用来解决它:
src="assets/jsPDF/dist/jspdf.js"
答案 1 :(得分:0)
您必须包含对FileSaver.min.js的引用