如何解决如何使用jsPDF为ejs文件的div内容生成pdf?
我正在尝试使用jsPDF为ejs文件的div内容生成PDF文件。但是我无法做到。下面是我生成该文件的代码。我正在创建一个包含姓名,电子邮件和电话的表单并提交后,我想生成pdf formate中的数据。让我知道我是否缺少某些东西,我已经安装了jsPDF。对于以下代码,出现错误“未定义jsPDF”。 app.js
app.get('/form1',function (req,res) {
res.render('form',{
title: "Login",action: "/form1",fields: [
{name:'Name',type:'text',property:'required'},{name:'Email',property:'required'}
{name:'Phone No',property:'required'}
]
});
});
ejs文件:-
<div id="content">
<form action="<%= action %>" method="post">
<% if (fields.length) { %>
<% fields.forEach(function(field){ %>
<label><%= field.name %></label>
<input type="<%= field.type %>" name="<%= field.name %>" <% if (field.property) { %>
<%= field.property %> <% } %> >
<% }) %>
<% } %>
<button type="submit"><%= title %></button>
</form>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>
<script>
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element,renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.fromHTML($('#content').html(),15,{
'width': 170,'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
</script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。