javascript - How do I create multiline text and page split in jspdf? -


i trying output text content of collection of text area inputs pdf file using jspdf. can't work out how put in line breaks or use pagesplit:true option doesn't take argument in doc.text. see similar question asked 25 days ago don't understand how implement answer , not sure work multiple text areas. appreciate advice.

<html> <title>multi-line/pagesplit</title> <body> <form action="#" method="post" id="myform">     <table id="mytable">         <tr>             <td>please enter text</td>         </tr>         <tr>             <td><textarea rows="4" cols="50" id="mytext" wrap="soft" placeholder="your text..."></textarea></td>         </tr>     </table> </form> <input type="button" value="download pdf" onclick="downloadpdf()"/></button> <script> function downloadpdf(){     var text = document.getelementbyid("mytext").value;     var doc = new jspdf();     doc.setfontsize(12);     doc.text(20, 20, text);     doc.save('test.pdf');     ; } </script> <script src="jspdf.min.js"></script> </body> </html> 

edit: found helpful answer here: word wrap in generated pdf (using jspdf)? , managed tweak needs. seems necessary plugins in jspdf.min.js. here's code i've ended using:

<!doctype html> <html> <title>multi-line/pagesplit</title> <body> <form action="#" method="post" id="myform">     <table id="mytable">         <tr>             <td>please enter text</td>         </tr>         <tr>             <td><textarea rows="4" cols="50" id="mytext" wrap="soft" placeholder="your text..."></textarea></td>         </tr>     </table> </form> <input type="button" value="download pdf" onclick="downloadpdf()"/>.     </button> <script> function downloadpdf(){     var text = document.getelementbyid("mytext").value;     var doc = new jspdf();     var splittext = doc.splittexttosize(text, 250);     var pageheight = doc.internal.pagesize.height;     doc.setfontsize(11);     var y = 20;     (var i=0; i<splittext.length; i++){         if (y > 275){             y = 20;             doc.addpage();         }         doc.text(20, y, splittext[i]);         y = y + 5;     }     doc.save('test.pdf');     ; } </script> <script src="jspdf.min.js"></script> </body> </html> 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -