title: Print/save page as PDF, but if an element would get cut off then add a page break before it
body: <p>I have a page that I need to print as a PDF (either save as a PDF or just use the browser print dialog), similar to this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>div {
    outline: red solid 1px;
  }
  body {
      margin-left: 30vw;
      margin-right: 30vw;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div&gt;
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  &lt;/div&gt;
  &lt;br&gt;
  &lt;div&gt;
  It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
  &lt;/div&gt;
  &lt;br&gt;
  &lt;div&gt;
  It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
  &lt;/div&gt;
  &lt;br&gt;
  &lt;div&gt;
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The contents of the site is longer that would fit in a single page, so it gets cut off when I try to print it. I want there to be a page break inserted before each segment if it would get cut in the middle, so that there are only page breaks in between the segments. I'm currently trying to use <code>html2pdf.js</code> with the avoid-all page break mode:</p>
  
  <pre><code>html2pdf().set({
    pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }
  });
  </code></pre>
  
  <p>But this doesn't seem to do anything. I could use the manual tagging (adding the class <code>html2pdf__page-break</code> to elements that should be before a page break), but I modify this site frequently, and I don't want to have to go back every time I make a change to the site that makes elements longer or shorter.</p>