用Javascript Apache Cordova创建PDF并通过电子邮件发送
Create and email PDF in Javascript Apache Cordova
我正在使用JavaScript和HTML为Android构建Apache Cordova应用程序。我希望用户点击/点击一个按钮,然后用他们刚刚输入到文本字段中的字符串生成一个PDF,然后打开一封电子邮件发送PDF附件。附件不需要保存到设备,但在发送之前如果需要,可以保存。这可能吗?如果可能,有关于如何做到这一点的文档或教程吗?
感谢
好的,为了实现这一点,我们需要添加一些输入并获取它的值,以及一个触发js的按钮。这很容易。
HTML:
<input type="text" id="name" placeHolder="Enter Your name" />
<input type="text" id="lname" placeHolder="Enter Your last name" />
<input type="text" id="hobby" placeHolder="Enter Your hobby" />
<input type="text" id="skills" placeHolder="Enter Your skills" />
<button id="btn">
Get results
</button>
<!--values will be shown inside the div#content-->
<div id="content"></div>
接下来是JavaScript部分,您将使用<p></p>
标记显示div#content
中的所有输入值。
JavaScript:
function onload() {
var input, btn, p, content, input_array;
//grab the button by ID
btn = document.getElementById("btn");
//grab all inputs
input = document.getElementsByTagName("INPUT");
//grab the div by ID
content = document.getElementById("content");
// Add some 'Data' inside the variable so that you show
// the user what he answered
input_array = [
"Name:",
"Last name:",
"Hobby:",
"Skills:"
];
//attach the click event listener to the button
btn.addEventListener("click", function() {
//Using the for loop, we basically create 4 <p> elements inside
//the div#content
for (var i = 0; i <= 3; i++) {
p = content;
// we display all of the input values within a <p> tag
// with a class of 'testing' so that you cn change it later
// on for styling it etc..
// Then we add the array and input values inside the <p> tag
p.innerHTML += "<p class='testing'>" + input_array[i] + " " + input[i].value + "</p>";
}
}, false);
}
//call the function
onload();
既然你已经展示了价值观,你就可以做很多事情了。你可以将用户写的所有内容存储到一个数组中,做一些很酷的动画并在结果中淡入淡出。
要将结果生成为PDF格式,你需要使用我在GitHub上发现的这个插件,据说它说用户可以保存生成的PDF。
(请注意,我个人以前没有使用过这个插件,所以我不保证。)
链接:cordova-plugin-html2pdf
按照那里的文档操作,一切都会很好。
演示:Jsfidle
相关文章:
- 如果我在javascript中输入无效的电子邮件或空白,如何显示特定的文本框边框红色
- 使用angularjs验证文本框中的电子邮件
- 使用正则表达式评估电子邮件地址时出现性能问题
- javascript中添加验证电子邮件的问题
- 以PDF附件的形式通过电子邮件发送谷歌文档
- 将Meteor中的base64 PDF作为电子邮件附件
- 谷歌应用程序将电子邮件表单脚本转换为PDF格式,但希望清除一些单元格
- Google Apps 脚本 - 将横向参数添加到 PDF 电子邮件附件
- PDF 表单 提交到电子邮件
- Rails 4/Ruby 2,Javascript 将 PDF 附加到电子邮件
- 用Javascript Apache Cordova创建PDF并通过电子邮件发送
- 如何使用本地Outlook从IIS网站通过电子邮件发送pdf
- nodejs pdfgit将动态生成的PDF附加到电子邮件(Mandrill-API)
- 如何通过谷歌电子表格内的脚本发送PDF电子邮件
- 发送电子邮件填写PDF表格
- 希望我格式化的DIV转换为PDF,并通过电子邮件发送在一个单一的点击.这可能吗?
- 如何通过电子邮件提交PDF
- 使用实时PDF发送电子邮件,无需发送附件
- 使用javascript/php将HTML表单转换为PDF和电子邮件
- 如何发送pdf文件,通过电子邮件id使用html,javascript和php