使用jsPDF从Iframe内容下载PDF文件

4
我希望保存一个包含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会出现以下错误:
Uncaught TypeError: Cannot read property 'widths' of undefined
可能的问题是什么?

1
你解决了这个问题吗? - gsgx
1个回答

9
添加 jspdf.plugin.standard_fonts_metrics.js

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接