title: Print table footer at very bottom of last page only at footer section
body: <p>I am trying to make footer stick to the bottom of the very last page only at the footer section of the print preview  </p>
  
  <p>The page content is dynamic so i dont know which is my last page.</p>
  
  <p>I have tried the below code and it makes the footer appears at the last page of the preview but not in footer section of the last page.currently the footer section prints at the page 2 which is immediate next to the body section but i want footer section to be printed at page 2 of the footer section</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-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js"&gt; &lt;/script&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          function printDiv(divID) {
              //Get the HTML of div
              var divElements = document.getElementById(divID).innerHTML;
              //Get the HTML of whole page
              var oldPage = document.body.innerHTML;
  
              //Reset the page's HTML with div's HTML only
              document.body.innerHTML =
                "&lt;html&gt;&lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt;&lt;body&gt;" +
                divElements + "&lt;/body&gt;";
  
              //Print Page
              window.print();
  
              //Restore orignal HTML
              document.body.innerHTML = oldPage;
  
  
          }
      &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;button onclick="myFunction()"&gt; Print this page&lt;/button&gt; &lt;input type="button" value="Print 1st Div" onclick="javascript:printDiv('printablediv')" /&gt; &gt;
      &lt;script&gt;
          function myFunction() {
              window.print();
          }
  
      &lt;/script&gt;
      &lt;div id="printablediv"&gt;
          &lt;table&gt;
              &lt;thead&gt;
                  &lt;tr style="height:30px;"&gt; &lt;th&gt; PAGE HEADER&lt;/th&gt; &lt;/tr&gt;
              &lt;thead&gt;
              &lt;tfoot&gt; &lt;tr&gt; &lt;td id="spacer" style="height:200px;"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tfoot&gt;
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt;
                          content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt;
                          content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt;
                          content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt;
                          content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt;
                          content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt;
                          content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt;
                          content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt; content&lt;br&gt;
  
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;        
  
          &lt;div id="footer" style="position:relative; bottom: 0;"&gt; Sample &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Please refer to my attached screenshot for reference<a href="https://i.stack.imgur.com/t8X8S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t8X8S.png" alt="enter image description here"></a></p>