Cannot make PDF from Html div by jsPDF

后端 未结 3 1970
抹茶落季
抹茶落季 2020-12-11 16:55

I have this js code :

var doc = new jsPDF();

$(\'#pdf_new\').click(function(){
    var html=$(\".wrap_all\").html();
    doc.fromHTML(html,200,200, {
              


        
3条回答
  •  一生所求
    2020-12-11 17:25

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

提交回复
热议问题