So this is my HTML code where I'm trying to get whatever is outputted in the div "abc" to a downloadable pdf file.
所以这是我的HTML代码,我试图将div“abc”中输出的内容输出到可下载的pdf文件中。
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Reports
</h1>
<ol class="breadcrumb">
<li>
<i class="fa fa-dashboard"></i> <a href="dashboard">Dashboard</a>
</li>
<li class="active">
<i class="fa fa-edit"></i> Reports
</li>
</ol>
<body>
<div id="abc">
</div>
<div id="editor"></div>
<button id="cmd">Download Survey Report</button>
<div id="abc">
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.3/jspdf.min.js"></script>
<script>
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.fromHTML($('#abc').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('SurveyReport.pdf');
});
</script>
<script>
firebase.auth().onAuthStateChanged(function(user){
if(user){
var userID = user.uid;
RetrieveSurvey(userID,1,PrintSurvey(document.getElementById("abc")));
}
})
</script>
</div>
</div>
And I'm getting this error on the console: "Uncaught ReferenceError: jsPDF is not defined"
我在控制台上收到此错误:“未捕获的ReferenceError:未定义jsPDF”
I am not sure what I'm doing wrong here, I even added jsPDF in the script tag...
我不确定我在这里做错了什么,我甚至在脚本标签中添加了jsPDF ...
1 个解决方案
#1
2
First of all your HTML is invalid. Check W3S.
首先,您的HTML无效。检查W3S。
Put your link to jspdf
inside <head>
tag, you can do it even inside <body>
tag.
将您的链接放在标签内的jspdf中,即使在标签内也可以。
Replace your jspdf
script with latest one:
用最新的jspdf脚本替换你的jspdf脚本:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script>
#1
2
First of all your HTML is invalid. Check W3S.
首先,您的HTML无效。检查W3S。
Put your link to jspdf
inside <head>
tag, you can do it even inside <body>
tag.
将您的链接放在标签内的jspdf中,即使在标签内也可以。
Replace your jspdf
script with latest one:
用最新的jspdf脚本替换你的jspdf脚本:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script>