0
I have a report where several tables are created separated by categories with specific header and footer that repeat.
I need to add a page numbering for the categories where in each new category this numbering is restarted and because of the variation in size and number of lines ends up making it impossible to do this counting via back-end.
To solve this situation I thought of using CSS "Counters" counters for page counting. Only I found a problem in the print view, since it is not possible to determine how many times the header or footer will repeat to make this page count.
In the print view you are not increasing the number of pages according to the table header. I tried using CSS @Page to increment the pages and use counter-reset on each table to restart the numbering, but the real problem is increasing the numbering of pages according to the category.
CSS
.report-table {
page-break-after: always;
counter-reset: page;
}
.report-header {
display: table-header-group;
}
.report-header tr th span.page-number:after {
counter-increment: page;
content: "Pag:" counter(page);
}
.report-footer {
display: table-footer-group;
}
HTML
<button onclick="window.print();">Print</button>
<table class="report-table">
<thead class="report-header">
<tr>
<th>conteudo</th>
<th>conteudo</th>
<th><span class="page-number"></span></th>
</tr>
</thead>
<tfoot class="report-footer">
<tr>
<td></td>
<td>valor</td>
<td>$ 0,00 </td>
</tr>
</tfoot>
<tbody>
<tr>
<td>conteudo</td>
<td>conteudo</td>
<td>conteudo</td>
</tr>
<tr>
<td>tabela</td>
<td>longa</td>
<td>aqui</td>
</tr>
<tr>
<td>conteudo</td>
<td>conteudo</td>
<td>conteudo</td>
</tr>
</tbody>
</table>
Jsfiddle
This article should interest you. https://www.smashingmagazine.com/2015/01/designing-for-print-with-css/ read on "PAGE BREAKS" and "Counters" which should have what you need
– hugocsl
Excellent article! It will certainly be very useful, but unfortunately it still does not solve the situation of the question. The problem happens in the print view (I did Edit to fix it). Page counting as the header repeats does not happen since it seems to be created only once, even if it is repeated several times in the print view.
– Johnatan Cunha
You may have multiple session titles, even if they are the same, but they will only appear on @-print. on @-screen you leave them hidden with display:None, only from display:block in @print css. For the title face of these that will appear you use the page-break to start face title on a different page, and put a counter for each title of these. If the system is small it can solve, but if it is too big this dynamic can be unfeasible.
– hugocsl