html - 关于打印 View 问题的 CSS 反增量页面

标签 html css html-table report reporting

我在浏览器的打印 View 上遇到页数问题。

创建一个包含按类别分隔的表格的报告我需要按类别重置计数器,当我们创建一个行数不确定的长数据表时,我们无法计算表头将显示多少次以确定有多少页面将具有该类别。

有没有办法在打印 View 中计算标题将显示多少次?

JSFiddle

https://jsfiddle.net/7prs03eh/3/

.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;
}
<button onclick="window.print();">Print</button>
<table class="report-table">
  <thead class="report-header">
    <tr colspan="3"> Category 1 </tr>
    <tr>
      <th>content</th>
      <th>content</th>
      <th><span class="page-number"></span></th>
    </tr>
  </thead>
  <tfoot class="report-footer">
    <tr>
      <td></td>
      <td>total</td>
      <td>$ 0,00 </td>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td>content</td>
      <td>content</td>
      <td>content</td>
    </tr>
    <tr>
      <td>long</td>
      <td>data</td>
      <td>here</td>
    </tr>
    <tr>
      <td>content</td>
      <td>content</td>
      <td>content</td>
    </tr>
  </tbody>
</table>

<table class="report-table">
  <thead class="report-header">
    <tr colspan="3"> Category 2 </tr>
    <tr>
      <th>content</th>
      <th>content</th>
      <th><span class="page-number"></span></th>
    </tr>
  </thead>
  <tfoot class="report-footer">
    <tr>
      <td></td>
      <td>total</td>
      <td>$ 0,00 </td>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td>content</td>
      <td>content</td>
      <td>content</td>
    </tr>
    <tr>
      <td>long</td>
      <td>data</td>
      <td>here</td>
    </tr>
    <tr>
      <td>content</td>
      <td>content</td>
      <td>content</td>
    </tr>
  </tbody>
</table>

最佳答案

恐怕用 css 添加计数打印数字不可能

如果 Firefox 是 MDN notes 的一个选项,您可能会解决这个问题。 :

Using CSS counter to print page numbers only works on Firefox. It’s unclear if the behavior is defined in the specification and whether or not it would be supported in other browsers at all. See issue filed with Chromium.

#print-foot:after {
    content: counter(page);
    counter-increment: page;
  }

查看完整 code snippet in JSFiddle .

请记住,虽然在 Firefox 中可行,但此功能将被视为 extremely buggy并且很难进行进一步的自定义和样式设置。此功能在浏览器内打印中是不可能的。

如果 服务器端 PDF 生成是一个选项,那么有几个库可以为您工作,例如 PDFjs , Prince等等。

关于html - 关于打印 View 问题的 CSS 反增量页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50681472/

相关文章:

html - Outlook CSS 渲染与浏览器不同

html - 如何用 CSS 放置 3 个色 block HTML

css - 是否可以在元素中插入边框,留下边距?

javascript - 从另一个文件分配特定文本以弹出显示 html

css - 100% 宽度 + 水平和垂直滚动

html - 使用 Adob​​e Business Catalyst 时的 Bootstrap 导航问题

html - 虚线表边框变为实线?

javascript - 将变量分配给单个表格单元格

html - 通过 CSS 隐藏列时如何修改 colspan 属性?

javascript - DIV 和表格 - 多行