Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

download PDF file from an Iframe content with jsPDF

i want to save a PDF file which contains an IFrame Content. I use the jsPDF Javascript library for.

Here is my Code as yet:

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');
}

when i try this i become this Error in Chrome:

Uncaught TypeError: Cannot read property 'widths' of undefined

What may be the problem ?

like image 677
aykon Avatar asked Jan 13 '23 10:01

aykon


1 Answers

Add jspdf.plugin.standard_fonts_metrics.js.

like image 196
Starbuck Avatar answered Jan 19 '23 13:01

Starbuck