title: CSS and HTML print setup for multi-page documents with running header and footer
body: <p>I am having nightmares figuring out how to properly set CSS and HTML layout for printing  documents in our web-app. We have different documents that come into the system (order, invoice, delivery notes, ...). The documents consist of:</p>
  
  <ul>
  <li>static header (company logo, contact info)</li>
  <li>body
  
  <ul>
  <li>customer data (shipping, billing address)</li>
  <li>items table (table with several rows, which can spread trough several pages)</li>
  </ul></li>
  <li>static footer (disclaimer)</li>
  </ul>
  
  <p>What I want is following print functionality:</p>
  
  <ul>
  <li>I want static header and footer to be printer on each page if the body spreads trough several pages</li>
  <li>The items table to have a table header printed in every page if it spreads in more pages</li>
  </ul>
  
  <p>Currently my HTML layout is like this:</p>
  
  <pre><code>&lt;!-- STATIC HEADER --&gt;
  &lt;div id="pageHeader"&gt;
      &lt;table class="table"&gt;
          &lt;tr&gt;
              &lt;td&gt;Static header content here&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  
  &lt;!-- DOCUMENT CONTENT --&gt;
  &lt;div id="pageBody"&gt;
  
      &lt;!-- Customer data --&gt;
      &lt;table class="table"&gt;
          &lt;tr&gt;
              &lt;td&gt;Customer data here&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
      &lt;!-- Items table --&gt;
      &lt;table class="table table-condensed table-print"&gt;
          &lt;thead style="display:table-header-group;"&gt;
              &lt;tr&gt;
                  &lt;th&gt;Table header here&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  &lt;td&gt;Rows here&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  
  &lt;/div&gt;
  
  &lt;!-- STATIC FOOTER --&gt;
  &lt;div id="pageFooter"&gt;
      &lt;table class="table"&gt;
          &lt;tr&gt;
              &lt;td&gt;Static footer content here&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I was reading about running headers and footers following answer on <a href="https://stackoverflow.com/questions/9729461/creating-page-headers-and-footers-using-css-for-print">this question</a> but I don't get the desired results. Currently my CSS is set like this:</p>
  
  <pre><code>#pageHeader, #pageFooter { display: none; }
  
  @media print {
      #pageHeader { display: block; position: running(pageHeader); width: 100%; }
      #pageFooter { display: block; position: running(pageFooter); width: 100%; }
  }
  
  @page {
      @top-center {
          content: element(pageHeader);
      }
  
      @bottom-center {
          content: element(pageFooter);
      }
  }
  </code></pre>
  
  <p>Firefox gives me completely strange results. It first prints a blank page, then the second page is ok if it's a single page document, if it's a multi-page document then it only prints first page, other pages are ignored.</p>
  
  <p>Google Chrome is slightly better. It prints all pages but it wont print static header and footer on every page. Header is printed only on first page, while footer only on last page.</p>
  
  <p>Also the other problem is that the main table that can spread trough several pages does not print table header in every page if the table spreads trough multiple pages. I thought that <code>display:table-header-group;</code> on <code>&lt;thead&gt;</code> supposed to do that? </p>
  
  <p>Is this just impossible to achieve or am I doing something completely wrong? If you can give me any advice or strategy on how to handle this I will be very happy. Since this app is running in controlled environment I can focus on one or two browsers (Chrome and Firefox would be great). If it works in both is bonus!</p>