最近怎么老写页面。。。。。。
样式:中间行会遍历打印
要求:分页时行不会被从中间切断,表格宽度可以按需调节。
中途遇到问题
- 由于中间使用了行合并使用tr标签page-break-inside: avoid !important;无效,会将合并的两行割裂。
- 直接设置td宽度,由于行合并导致部分宽度失效。
问题图片
图1
图2
总结
最终使用三个table并且table标签使用page-break-inside: avoid !important;循环遍历中间table不会割裂table。
表格样式固定
- 使用第一行设置宽度,并且设置第一样高度为0,已通过。
- 咨询前端使用<colgroup>和<col width='3%'>固定样式发现在转为pdf时样式失效,待找原因。
最终效果图
代码验证可行
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Template</title>
<style type="text/css">
table {
border-collapse: collapse;
-fs-table-paginate: paginate;
table-layout: fixed;
page-break-inside: avoid !important;
width: 100%;
}
tr,
td {
word-wrap: break-word;
word-break: break-all;
border: 1px #000000 solid;
}
body {
margin: 5px;
padding: 0;
font-size: 13px;
}
</style>
<body>
<table>
<tbody>
<tr>
<td width="3%" rowspan="2">Sr No</td>
<td width="9%" rowspan="2">Part No</td>
<td width="9%" rowspan="2">HSN/SAC</td>
<td width="4%" rowspan="2">Qty</td>
<td width="3%" rowspan="2">Unit</td>
<td width="9%" rowspan="2">Rate</br>(per item)</td>
<td width="9%" rowspan="2">Taxable</br>value</td>
<td width="9%" colspan="2">IGST</td>
<td width="9%" colspan="2">CGST</td>
<td width="9%" colspan="2">SGST</td>
<td width="9%" colspan="2">Compensation Cess</td>
<td width="9%" colspan="2">Refund to be claimed</td>
<td width="9%" rowspan="2">Total Value</td>
</tr>
<tr>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
</tr>
</tbody>
</table>
<table style="border-spacing:0;margin-top:-1px;margin-bottom:-1px;border-top:0px">
<tbody>
<tr style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px">
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='3%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='9%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='9%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='3%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='9%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='9%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='4.5%'></td>
<td style="border:0;padding:0;height:0;margin-top:-1px;margin-bottom:-1px" width='9%'></td>
</tr>
<tr>
<td rowspan="2" width="3%">${itemx.BillingItemNumber}</td>
<td rowspan="2" width="9%">${itemx.govDummyNumber}</td>
<td colspan="16" text-align="left">Lease Rental Charges for
${itemx.DummyNumber} ${itemx.SKUName}
</td>
</tr>
<tr>
<td>${itemx.controlCode}</td>
<td>${itemx.qty}</td>
<td>EA</td>
<td>${itemx.unitprice}</td>
<td>${itemx.totalCharge}</td>
<td>${itemx.taxRate0} %</td>
<td>${itemx.tax0}</td>
<td>${itemx.taxRate1} %</td>
<td>${itemx.tax1}</td>
<td>${itemx.taxRate2} %</td>
<td>${itemx.tax2}</td>
<td>${itemx.taxRate3} %</td>
<td>${itemx.tax3}</td>
<td>${itemx.taxRate4} %</td>
<td>${itemx.tax4}</td>
<td>${itemx.amount}</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr style="border:0;padding:0;height:0">
<td style="border:0;padding:0;height:0" width='3%'></td>
<td style="border:0;padding:0;height:0" width='9%'></td>
<td style="border:0;padding:0;height:0" width='9%'></td>
<td style="border:0;padding:0;height:0" width='4%'></td>
<td style="border:0;padding:0;height:0" width='3%'></td>
<td style="border:0;padding:0;height:0" width='9%'></td>
<td style="border:0;padding:0;height:0" width='9%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='4.5%'></td>
<td style="border:0;padding:0;height:0" width='9%'></td>
</tr>
<tr style="margin-top:-1px;">
<td colspan="6">Total</td>
<td>${HtmlInvoice.totalCharge[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax1[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax2[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax3[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax4[1]}</td>
<td> ${HtmlInvoice.totalAmount[1]}</td>
</tr>
</tbody>
</table>
</body>
</html>
代码咨询前端,转pdf时有问题,但html正常
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Template</title>
<style type="text/css">
table {
border-collapse: collapse;
-fs-table-paginate: paginate;
table-layout: fixed;
page-break-inside: avoid !important;
width: 100%;
}
tr,td {
word-wrap: break-word;
word-break: break-all;
border:1px #000000 solid;
}
body {
margin: 5px;padding: 0;
font-size: 13px;
}
</style>
<body>
<table>
<tbody>
<tr>
<td width="3%" rowspan="2">Sr No</td>
<td width="9%" rowspan="2">Part No</td>
<td width="9%" rowspan="2">HSN/SAC</td>
<td width="4%" rowspan="2">Qty</td>
<td width="3%" rowspan="2">Unit</td>
<td width="9%" rowspan="2">Rate</br>(per item)</td>
<td width="9%" rowspan="2">Taxable</br>value</td>
<td width="9%" colspan="2">IGST</td>
<td width="9%" colspan="2">CGST</td>
<td width="9%" colspan="2">SGST</td>
<td width="9%" colspan="2">Compensation Cess</td>
<td width="9%" colspan="2">Refund to be claimed</td>
<td width="9%" rowspan="2">Total Value</td>
</tr>
<tr>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
<td width="5%">Rate</td>
<td width="4%">Amt</td>
</tr>
</tbody>
</table>
<table
style="border-spacing:0;margin-top:-1px;margin-bottom:-1px">
<tbody>
<colgroup>
<col width='3%'>
<col width='9%'>
<col width='9%'>
<col width='4%'>
<col width='3%'>
<col width='9%'>
<col width='9%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='9%'>
</colgroup>
<tr>
<td width="3%" rowspan="2">${itemx.BillingItemNumber}</td>
<td width="9%" rowspan="2">${itemx.govDummyNumber}</td>
<td colspan="16" text-align="left">Lease Rental Charges for ${itemx.DummyNumber} ${itemx.SKUName}</td>
</tr>
<tr>
<td>${itemx.controlCode}</td>
<td>${itemx.qty}</td>
<td>EA</td>
<td>${itemx.unitprice}</td>
<td>${itemx.totalCharge}</td>
<td>${itemx.taxRate0} %</td>
<td>${itemx.tax0}</td>
<td>${itemx.taxRate1} %</td>
<td>${itemx.tax1}</td>
<td>${itemx.taxRate2} %</td>
<td>${itemx.tax2}</td>
<td>${itemx.taxRate3} %</td>
<td>${itemx.tax3}</td>
<td>${itemx.taxRate4} %</td>
<td>${itemx.tax4}</td>
<td>${itemx.amount}</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<colgroup>
<col width='3%'>
<col width='9%'>
<col width='9%'>
<col width='4%'>
<col width='3%'>
<col width='9%'>
<col width='9%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='4.5%'>
<col width='9%'>
</colgroup>
<tr>
<td colspan="6">Total</td>
<td>${HtmlInvoice.totalCharge[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax1[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax2[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax3[1]}</td>
<td> </td>
<td>${HtmlInvoice.tax4[1]}</td>
<td> ${HtmlInvoice.totalAmount[1]}</td>
</tr>
</tbody>
</table>
</body>
</html>