在 html 到 pdf 的每个页面上重复用户信息

问题描述 投票:0回答:1

我正在使用 NReco PdfGenerator 来开发客户报表。为此准备了 html,然后将其转换为 PDF。 在生成的 pdf 中有用户信息部分和声明部分。

目前当记录数量增加时,报表部分会重复到其他页面,而用户信息部分仅显示在第一页。但我还需要在每一页中重复用户信息部分。

这是我的html

<b>User Information Section</b>
    <table style="border-collapse: collapse; width: 100%; border-style: none;" cellspacing="0" cellpadding="0">
        <tbody>
            <tr style="padding-right: 15px; font-family: Cairo ; font-size: 12pt;">
                <td style="width:">
                    <table>
                        <tbody>
                            <tr>
                                <td style="font-size:11pt;font-weight:bold">Name</td>
                                
                                <td>:</td>
                            </tr>
                        </tbody>

                    </table>

                </td>
                <td style="width:">

                    <div style="text-align: left;font-size: 11pt;padding-left: 10px;padding-right: 10px;font-weight:bold">
                        jeorge
                    </div>
                </td>
                
            </tr>
            <tr style="padding-right: 15px; font-family: Cairo ; font-size: 12pt;">
                <td style="width:">
                    <table>
                        <tbody>
                            <tr>
                                <td style="font-size:11pt;font-weight:bold">Cus NO</td>
                                
                                <td>:</td>
                            </tr>
                        </tbody>

                    </table>

                </td>
                <td style="width:">

                    <div style="text-align: left;font-size: 11pt;padding-left: 10px;padding-right: 10px;font-weight:bold">
                        445026
                    </div>
                </td>
                
                <td style="width:">

                    <table>
                        <tbody>
                            <tr>
                                <td style="font-size:11pt;font-weight:bold">Date</td>
                                
                                <td>:</td>
                            </tr>
                        </tbody>

                    </table>
                </td>
                <td style="width: ">

                    <div style="text-align: left;font-size: 11pt;padding-left: 10px;padding-right: 10px;font-weight:bold">
                        30/11/22
                    </div>
                </td>
                
            </tr>
            <tr style="padding-right: 15px; font-family: Cairo ; font-size: 12pt;">
                <td style="width:">

                    <table>
                        <tbody>
                            <tr>
                                <td style="font-size:11pt;font-weight:bold">Invoice No</td>
                                <td></td>
                                <td>:</td>
                            </tr>
                        </tbody>

                    </table>
                </td>
                <td style="width:">

                    <div style="text-align: left;font-size: 11pt;padding-left: 10px;padding-right: 10px;font-weight:bold">
                        1094093
                    </div>
                </td>
                
                <td style="width:">

                    <table>
                        <tbody>
                            <tr>
                                <td style="font-size:11pt;font-weight:bold"><b>Page No</b></td>
                                
                                <td>:</td>
                            </tr>
                        </tbody>

                    </table>
                </td>
                <td style="width: ">
                    <div id="pageCounter">
                        <span></span>
                    </div>
                    <div id="pageNumbers" style="text-align: left;font-size: 11pt;padding-left: 10px;padding-right: 10px;font-weight:bold">
                        <div></div>
                    </div>
                </td>
                
            </tr>


        </tbody>
    </table>
    <br />
    <b>Statement Section</b>
    <table style="border-collapse: collapse;width: 100%;border-width: thin;color:black;margin-top:1px" border="1" bordercolor="black" cellspacing="0" cellpadding="0">
        <thead>
            <tr style="background-color: #f1f1f1;font-family: Cairo ;color: black;font-size:11pt;font-weight:bold">
                <td style="width: 5%;  text-align: center; ">
                    
                    <br /> Cust_No
                </td>
                
                <td style="width: 10%;  text-align: center;font-size:11pt;font-weight:bold">
                    
                    <br />Date
                </td>
                <td style="width: 10%;  text-align: center;font-size:11pt;font-weight:bold ">
                    
                    <br /> Qty
                </td>
                <td style="width: 10%;  text-align: center;font-size:11pt;font-weight:bold">
                    
                    <br /> Price
                </td>
                
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td style="width: 10%; border: solid windowtext 1pt; border-top: none;border-right:none; border-color: black;"></td>
                <td style="width: 40%; border-top: none; border-left: none;border-right:none;  border-bottom: solid windowtext 1pt;border-color: black;"></td>
                <td style="width: 15%; border-top: none; border-left: none; border-bottom: solid windowtext 1pt; border-right:none; border-color: black;"></td>
                <td style="width: 10%; border-top: none; border-left: none; border-bottom: solid windowtext 1pt; border-right: none;border-color: black;"></td>
                
                
            </tr>
        </tfoot>
        <tbody>
            <tr>
            <tr class="table_cell" style="font-family: Cairo ;font-size:9.5pt;line-height:0.5;">
                <td class="table_cell" style="width: 10%;color:black;border-color:black">
                    676767
                </td>
                
                <td class=" table_cell" style="width: 15%;color:black;border-color:black">
                    01/11/22
                </td>
                <td class="table_cell" style="width: 10%;text-align:right;color:black;border-color:black">
                    1
                </td>
                <td class="table_cell" style="width: 10%;text-align:right;color:black;border-color:black">
                    290.70
                </td>
                
            </tr>
            <tr class="table_cell" style="font-family: Cairo ;font-size:9.5pt;line-height:0.5;">
                <td class="table_cell" style="width: 10%;color:black;border-color:black">
                    353535
                </td>
                
                <td class=" table_cell" style="width: 15%;color:black;border-color:black">
                    02/11/22
                </td>
                <td class="table_cell" style="width: 10%;text-align:right;color:black;border-color:black">
                    1
                </td>
                <td class="table_cell" style="width: 10%;text-align:right;color:black;border-color:black">
                    343.81
                </td>
                
            </tr>

        </tbody>
    </table>

和 CSS

body {
            margin: 20px;
        }

        table {
            page-break-inside: auto;
        }

        tr {
            page-break-inside: avoid;
            page-break-after: auto;
        }

        thead {
            display: table-header-group;
        }

        tfoot {
            display: table-footer-group;
        }

        #content {
            flex: 1 1 auto;
        }

除此之外,我还需要在用户信息部分的 PageNo 字段中显示页码。

你能帮忙吗? TIA.

我将两者都保存在一个 Div 中并添加了

.divRepeat{
            display: table-header-group;
        }

但没有按预期工作。

c# css pdf html-to-pdf nreco
1个回答
0
投票

首先,我可能建议完全避免使用嵌套表( 在外部表的单元格内),因为 wkhtmltopdf 只能在外部表级别正确处理分页符。为避免单元格内出现分页符,请使用

page-break-inside:avoid
.

要重复表格的标题行,用

包裹标题的 就足够了,并使用 作为“数据”行。

要在每一行上呈现“用户信息部分”,您可以:

变体1:尝试将此内容包含在

中,像那样:

<thead>
  <tr>
    <td colspan="4">User information Section ...</td>
  </tr>
  <tr>
    <th>Cust No</th><th>Date</th> ...
  </tr>
</thead>

变体 2:简单地在 PDF 页面标题中呈现“用户信息部分”(HtmlToPdfConverter.PageHeaderHtml 属性)

© www.soinside.com 2019 - 2024. All rights reserved.