Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this js code :

var doc = new jsPDF();

$('#pdf_new').click(function(){
    var html=$(".wrap_all").html();
    doc.fromHTML(html,200,200, {
        'width': 500,
    });
    doc.save("Test.pdf");
});

In html I have code like this :

<div class = 'wrap_all'>
    <div id = 'wrap_odd'> <div id = ''>....</div> </div>

    <div id = 'wrap_even'> <div id = ''>....</div> </div>
</div>

Nothing works ... Console return to me:

Cannot read property #wrap_odd of undefined"

(P.S sorry for my English)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
501 views
Welcome To Ask or Share your Answers For Others

1 Answer

When using 'fromHTML' to take text from a HTML from for the PDF you are creating using JSPDF, you should have an elementHandler function to render out the unwanted < div >.

Try following the same patern as shown in the example at JSPDF@GitHub.

your end code should look like this:

var doc = new jsPDF();

    var specialElementHandlers = {
      'DIV to be rendered out': function(element, renderer){
       return true;
    }
    };


    $('#pdf_new').click(function(){
      var html=$(".wrap_all").html();
         doc.fromHTML(html,200,200, {
            'width': 500,
            'elementHandlers': specialElementHandlers
         });
      doc.save("Test.pdf");
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...