【发布时间】:2021-02-07 09:58:12
【问题描述】:
我需要使用 puppeteer 呈现发票 PDF,其中包含一个包含项目的表格。这些项目可以包含描述/cmets/等。 表格溢出到它下面的下一个 div 上。如果它溢出,行为应该进入下一页。
我尝试了很多 css break-* 和 @page 都没有运气,最大高度,但是表格并没有完全可见,还有很多其他的东西。我应该跳槽而只使用 div 吗?
.pdf {
background-color: #FFF;
overflow: hidden !important;
display: grid;
grid-template-rows: 190px minmax(10px, 246px) 786px 212px 1fr;
grid-row-gap: 1em;
}
.table-container {
table { page-break-inside: auto }
tr { page-break-inside: avoid; page-break-after: auto }
thead { display: table-header-group }
tfoot { display: table-footer-group }
}
table {
width: 100%;
border-spacing: 0;
border-collapse: collapse;
}
// ... other elms ...
<div class="pdf">
<header>
... company header logo and other details ...
</header>
<div class="details">
... invoice details ...
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th class="text-left">PRODUCT</th>
<th class="text-left">DESCRIPTION</th>
<th class="text-right">PRICE</th>
<th class="text-right">UNIT</th>
<th class="text-right">QUANTITY</th>
<th class="text-right">TOTAL</th>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
</div>
<div class="details">
this div gets overflowed
</div>
</div>
【问题讨论】:
-
你试过pdfmake.org吗?
-
很遗憾我无法更改当前系统。
-
可能有点牵强,但this answer 解决了针对不同页面自动破坏表格的问题。
-
这是一个很好的线索。我会试试看!谢谢@Chiel