gpt4 book ai didi

javascript - 使用按钮创建 PDF 以对 HTML 表单中输入的数据进行屏幕截图

转载 作者:太空宇宙 更新时间:2023-11-04 11:17:06 25 4
gpt4 key购买 nike

Form Created

您好,我正在考虑创建一个按钮,该按钮将以 PDF 格式捕获用户数据。然后需要保存并通过电子邮件发送(所附图片是此 PDF 文档中需要包含的内容的示例)

我目前的代码是用 HTML 和 JavaScript 编写的

最佳答案

有很多选择。

可以使用jsPDF、phantomJS

jsPDF 的 fiddle 示例

http://jsfiddle.net/cn18yyza/

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com