title: How do I create multiline text and page split in jspdf?
body: <p>I am trying to output the text content of a collection of text area inputs as a pdf file using jspdf. I can't work out how to put in line breaks or use the pagesplit:true option as it doesn't take it as an argument in doc.text. I see the a similar question was asked 25 days ago but I don't understand how to implement the answer and am not sure it would work for multiple text areas. I would greatly appreciate any advice.</p>
  
  <pre><code>&lt;html&gt;
  &lt;title&gt;Multi-line/pagesplit&lt;/title&gt;
  &lt;body&gt;
  &lt;form action="#" method="post" id="myForm"&gt;
      &lt;table id="myTable"&gt;
          &lt;tr&gt;
              &lt;td&gt;Please enter text&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;textarea rows="4" cols="50" id="myText" wrap="soft" placeholder="Your text..."&gt;&lt;/textarea&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  &lt;input type="button" value="Download as PDF" onclick="downloadPDF()"/&gt;&lt;/button&gt;
  &lt;script&gt;
  function downloadPDF(){
      var text = document.getElementById("myText").value;
      var doc = new jsPDF();
      doc.setFontSize(12);
      doc.text(20, 20, text);
      doc.save('Test.pdf');
      ;
  }
  &lt;/script&gt;
  &lt;script src="jspdf.min.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>EDIT: I found a really helpful answer here: <a href="https://stackoverflow.com/questions/24272058/word-wrap-in-generated-pdf-using-jspdf">Word wrap in generated PDF (using jsPDF)?</a> and managed to tweak it slightly for my needs. It seems that the necessary plugins were already in jspdf.min.js. Here's the code I've ended up using:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;title&gt;Multi-line/pagesplit&lt;/title&gt;
  &lt;body&gt;
  &lt;form action="#" method="post" id="myForm"&gt;
      &lt;table id="myTable"&gt;
          &lt;tr&gt;
              &lt;td&gt;Please enter text&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;textarea rows="4" cols="50" id="myText" wrap="soft" placeholder="Your text..."&gt;&lt;/textarea&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  &lt;input type="button" value="Download as PDF" onclick="downloadPDF()"/&gt;.     &lt;/button&gt;
  &lt;script&gt;
  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;
      for (var i=0; i&lt;splitText.length; i++){
          if (y &gt; 275){
              y = 20;
              doc.addPage();
          }
          doc.text(20, y, splitText[i]);
          y = y + 5;
      }
      doc.save('Test.pdf');
      ;
  }
  &lt;/script&gt;
  &lt;script src="jspdf.min.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>