javascript - Exporting multiple divisions in html file to PDF using JSPDF -
i working on requirement need export html file pdf on button click. html file having multiple divisions , have export selected divisions pdf after converting them canvas-image. bit new jspdf , html2canvas libraries, below code working fine single division. please suggest changes in order handle multiple div export pdf.
<button id="btn">generate pdf</button> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript" src="//cdn.rawgit.com/mrrio/jspdf/master/dist/jspdf.min.js"></script> <script type="text/javascript" src="//cdn.rawgit.com/niklasvh/html2canvas/0.5.0-alpha2/dist/html2canvas.min.js"></script> <script type="text/javascript" > (function(){ var form = $('.test'), cache_width = form.width(), a4 =[ 595.28, 841.89]; // a4 size paper width , height $('#create_pdf').on('click',function(){ $('body').scrolltop(0); createpdf(); }); //create pdf function createpdf(){ getcanvas().then(function(canvas){ var img = canvas.todataurl("image/png"), doc = new jspdf({ unit:'px', format:'a4' }); doc.addimage(img, 'jpeg', 20, 20); doc.save('techumber-html-to-pdf.pdf'); form.width(cache_width); }); } // create canvas object function getcanvas(){ form.width((a4[0]*1.33333) -80).css('max-width','none'); return html2canvas(form,{ imagetimeout:2000, removecontainer:true }); } }()); </script> </body> </html>
"test" class name of 1 div in form not able use below code multiple divs
Comments
Post a Comment