title: How to set a page break in MPDF
body: <p>I am trying to create a page break in mPDF, but not succeeding, regardless of following every possible manual instruction, with the current attempt using this info:</p>
  
  <p><a href="https://mpdf.github.io/reference/html-control-tags/pagebreak.html" rel="nofollow noreferrer">https://mpdf.github.io/reference/html-control-tags/pagebreak.html</a></p>
  
  <p><strong>I am using mPDF version 8.0.2.</strong></p>
  
  <p>My current attempt looks like this:</p>
  
  <pre><code>function pdf_generate_table_html($data)
  {
      $page_length = 40;
      $pages = ceil(count($data) / $page_length);
      $keys = array_keys($data[0]);
      $html = '';
      $counter = 0;
      for ($i = 1; $i &lt;= $pages; $i++) {
          $slice = array_slice($data, $counter, $page_length, true);
          $html .= '&lt;table style="width: 100%; border: 1px solid #dddddd;"&gt;';
          $html .= '&lt;thead&gt;';
          $html .= '&lt;tr&gt;';
          foreach($keys as $key) {
              $html .= '&lt;th class="content" style="padding: 8px; background-color: #333333; color: #ffffff;"&gt;' . $key . '&lt;/th&gt;';
          }
          $html .= '&lt;/tr&gt;';
          $html .= '&lt;/thead&gt;';
          $html .= '&lt;tbody&gt;';
          foreach($slice as $key =&gt; $entry) {
              $html .= '&lt;tr&gt;';
              foreach($entry as $value) {
                  $html .= '&lt;td class="content" style="padding: 8px;"&gt;' . $value . '&lt;/td&gt;';
              }
              $html .= '&lt;/tr&gt;';
          }
          $html .= '&lt;/tbody&gt;';
          $html .= '&lt;/table&gt;';
          $html .= '&lt;pagebreak&gt;';
          $counter += $page_length;
      }
      return $html;
  }
  </code></pre>
  
  <p>The following happens:</p>
  
  <ol>
  <li><p>Without the page break and the code that slices the data into separate tables,  the first page contains the header, second page contains ENTIRE table (and I want it split...).</p></li>
  <li><p>With the page break, first page is blank, second page contains the header, third page contains 3 tables, correctly split, but resized and fit onto one page, fourth page is blank.</p></li>
  </ol>
  
  <p><strong>Important:</strong> Using <code>&lt;div&gt;</code> tags does not appear to be feasible for me, because I am using tabular data that may contain any number of columns, and I cannot find a way to force all columns to be the width of the widest item in a column.</p>
  
  <p>Any idea what I am doing wrong, please?</p>