openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

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

Open 429748372 opened this issue 3 years ago • 3 comments

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;

429748372 avatar Aug 08 '21 15:08 429748372

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>

danfickle avatar Aug 09 '21 05:08 danfickle

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>

rafgal avatar Sep 13 '21 20:09 rafgal

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.

seankanderson avatar Apr 03 '22 20:04 seankanderson