2016-05-27 2 views
1

Ich erstelle einen Studentenausweis und dann erstelle ich einen Button darunter, um ein zu geben Option für den Benutzer zum Herunterladen der ID-Karte als PDF.Ich bekomme "Uncaught TypeError: Kann die Eigenschaft 'childNodes' undefined 'Fehler nicht lesen, wenn ich jspdf zum Herunterladen von HTML div Inhalt als pdf

Meine ID-Karte div ist wie folgt:

 <!doctype html>    
     <html> 
     <head> 
     <title>Admin Registration</title> 
     <script src="js/jquery.min.js"></script> 
     <script src="js/show_message.js"></script> 
     <script type="text/javascript" src="js/jspdf.min.js"></script> 
     <script type=\"text/javascript\"> 
     $(document).ready(function() { 
     var doc = new jsPDF(); 
     var specialElementHandlers = { 
     '#editor': function (element, renderer) { 
     return true; 
     } 
     }; 

     $('#cmd').click(function() { 

      doc.fromHTML($('receipt-outer').html(), 15, 15, { 
      'width': 170,\n" + 
      'elementHandlers': specialElementHandlers 
      }); 
      doc.save('sample-file.pdf'); 
      }); 
     }); 
    </script> 
    </head> 

    <body> 

    <div class='receipt-outer'> 
    <div class="receipt-inner">   
    <div class='idcard_heading'><p>Student ID Card</p></div>  
    <div class='clear'></div> 
    <div class='receipt_details'> 
    <div class='idcard_heading1'> 
    <div class='id_pic'> 

    <div class='id_pic_inner'> 
    <img src='images/pic"+fno+".jpg' height='120px' width='140px'><br> 
    <img src='images/sign"+fno+".jpg' height='50px' width='140px'> 
    </div> 

    <table id='id_table'>"+ 
    <tr><th>Name : </th><td>"+s_fname+" "+s_mname+" "+s_sname+"</td></tr>     
    <tr><th>Course Name : </th><td>"+cname+"</td></tr> 
    <tr><th>Course code : </th><td>"+ccode+"</td></tr>       
    <tr><th>Commence of course : </th><td>"+st_from+"</td></tr> 
    <tr><th>End of course : </th><td>"+till+"</td></tr> 
    <tr><th>Timing : </th><td>"+ctiming+"</td></tr>      
    </table> 
    </div><br> 
    <div style='height:30px; margin-top:20px; margin-right:20px;'> 
    <span style='float:right;'>Issuing Authority</span></div> 

    <div id='editor'></div> 

    </div> 

    </div> 
    </div><br><br> 
    <button id='cmd'>Download </button> 

    </div> 

    </body> 
    </html> 

Ich mag den Teil des div vom div class beginnend zum Download = „Eingang-Außen“ bis zum Ende im PDF-Format, ohne nur den Download Taste.

Also habe ich die Datei jspdf.min.js importiert und ein Skript erstellt, das auf das click-Ereignis hört und dann das div als pdf herunterlädt. Aber ich bekomme den oben erwähnten Fehler in der Konsole, wenn ich den Download-Knopf drücke.

Bitte sagen Sie mir, wo ich falsch gelaufen bin. Warum ist es nicht meine Datei als pdf Download

+1

Vielleicht wird dies helfen http://stackoverflow.com/questions/17293135/download-a-div-in-einem-html-page-as-pdf-using-javascript – jakob

Antwort

Verwandte Themen