danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!
https://danfickle.github.io/pdf-templates/index.html
Other
1.93k stars 359 forks source link

Can not set div as header when the HTML print have more than one page. #742

Open 429748372 opened 3 years ago

429748372 commented 3 years ago

we want to set a div as a header when we generate pdf. but, the div can not be see in the new page when the table data have more data. example

<div>
<img></img>
<span>this is a header</span>
</div>
<table>
<tr></tr>
<tr>
<td></td>
</tr>
</table>

I have the the table -fs-table-paginate: paginate; -fs-page-break-min-height: 160px;

danfickle commented 3 years ago

Hi @429748372,

Table headers should be in a thead element, something like:

<table>
  <thead>
    <tr>
     <!-- Use colspan to span all columns in table. -->
     <th colspan="1">
       <div>
         <img></img>
         <span>this is a header</span>
       </div>
     </th>
    </tr>
  </thead>
  <tbody>
   <tr>
     <td></td>
   </tr>
  </tbody>
</table>
rafgal commented 3 years ago

You can use css-rule @page

@page {
  margin: 10mm;
  @top-right {
    content: element(head);
  }
}

.head{
  position: running(head);
}

<div class="head">
  <img></img>
  <span>this is a header</span>
</div>
<table>
  <tr></tr>
  <tr>
    <td></td>
  </tr>
</table>
seankanderson commented 2 years ago

FYI: If you have a large/complex running header or footer made out tables etc... you need to increase the page's top/bottom margin to accommodate the entire element. I was doing this without setting the margin (and I was testing with no margin!) and so I was seeing nothing...even though the element technically renders--you just can see it because it is off the page.