您好,我正在考虑创建一个按钮,该按钮将以 PDF 格式捕获用户数据。然后需要保存并通过电子邮件发送(所附图片是此 PDF 文档中需要包含的内容的示例)
我目前的代码是用 HTML 和 JavaScript 编写的
最佳答案
有很多选择。
可以使用jsPDF、phantomJS
jsPDF 的 fiddle 示例
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#customers')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 10,
width: 700
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('Test.pdf');
}, margins);
}
关于javascript - 使用按钮创建 PDF 以对 HTML 表单中输入的数据进行屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45342422/