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

标签 javascript java html pdf button

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/

相关文章:

JavascriptInterface 与 Phonegap。 (安卓网络应用程序)

java - mapstruct 中的映射循环问题

javascript - 创建一个像 html 复选框一样的 div

javascript - 使用iron-ajax (Google Polymer) 上传文件

javascript - 含义 - "//= require angular/angular"

javascript - 为什么在动态加载数据时 jqGrid 不显示第二页?

java - @Before 注释在 espresso 测试中被 kotlin 忽略?

java - 智能 : Cannot import classes from other modules in my project?

php - HTML5 表单验证机制 : set invalidate after server side validation

javascript - HTML5 将多个文本框存储到本地存储