【问题标题】:download PDF file from an Iframe content with jsPDF使用 jsPDF 从 Iframe 内容下载 PDF 文件
【发布时间】:2013-05-01 04:44:48
【问题描述】:

我想保存一个包含 IFrame 内容的 PDF 文件。我使用 jsPDF Javascript 库。

这是我的代码:

function toPDF(){       
        var pdf = new jsPDF('p', 'in', 'letter');

    // source can be HTML-formatted string, or a reference
    // to an actual DOM element from which the text will be scraped.
    source = $('#iframeid')[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
        '#emptyid': function(element, renderer){
            // true = "handled elsewhere, bypass text extraction"
            return true
        }
    }

    // all coords and widths are in jsPDF instance's declared units
    // 'inches' in this case
    pdf.fromHTML(
        source // HTML string or DOM elem ref.
        , 0.5 // x coord
        , 0.5 // y coord
        , {
            'width':7.5 // max width of content on PDF
             ,'elementHandlers': specialElementHandlers
        }
    )

    pdf.save('Test.pdf');
}

当我尝试这个时,我在 Chrome 中变成了这个错误:

未捕获的类型错误:无法读取未定义的属性“宽度”

可能是什么问题?

【问题讨论】:

  • 你发现了吗?

标签: javascript pdf jspdf


【解决方案1】:

添加jspdf.plugin.standard_fonts_metrics.js。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2019-11-28
    相关资源
    最近更新 更多