title: Autopaging jspdf when content increases
body: <p>I'm trying to create a pdf that auto-pages when a content increases.
  This is my sample code. Any help would be greatly appreciated :)</p>
  
  <p>HTML code</p>
  
  <pre><code>&lt;div *ngFor="let data of data"&gt;
    &lt;button click = "previewPdf(data)"&gt; Preview &lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>previewPdf(data) {
    var doc = new jsPDF();
    let bodyContent = doc.splitTextToSize(data.body, 250);
    let lineheight = 6;
    let offsety = 5;
  
    this.data.forEach(function(i) {
    doc.setFontSize(20);
    doc.text(10,10 + lineheight * 0 + offsety, bodyContent);
    doc.output("dataurlnewwindow");
  });
  
  }
  
  </code></pre>
  
  <p>JSON</p>
  
  <pre><code>data[{
    "body": "A very long letter content...";
  }];
  </code></pre>
  
  <p><strong>Edit</strong>:
  I have tried this sample code below and its giving me 2 pages and the last page is blank</p>
  
  <pre><code>previewPdf(data) {
      var doc = new jsPDF('p', 'mm', 'a4');
      let pageHeight = doc.internal.pageSize.getHeight();
      let bodyContent = doc.splitTextToSize(data.body, 250);
      let lineheight = 6;
      let offsetY = 5;
  
  
      doc.text(10, 10, bodyContent);
      // Before adding new content
      let y = 840; // Height position of new content
      if (y &gt;= pageHeight) {
        doc.addPage();
        y = 0 // Restart height position
      }
  
  
      // this.data.forEach(function(i) {
      //   doc.setFontSize(20);
      //   
      // });
      doc.output("dataurlnewwindow");
    }
  
  </code></pre>