TCPDF table 在多页上有边距

TCPDF table on multiple page with margin

我有一个动态变化的 table。因此,table 可以在多个页面上。

我在不中断行的情况下成功地更改了页面,但我遇到了有关文档 header 的问题。 table 在第二页继续,但从顶部开始,忽略文档中为徽标设置的边距。

这是我的代码

$html = '<br/>
        <table cellpadding="1" cellspacing="2" cellpadding="5" border="0" style="text-align:center;">
            <thead>
                <tr>
                    <th colspan="4" style="border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c; border-right:0.5px solid #1d2e5c;" bgcolor="#1d2e5c"><font color="#ffffff">&Eacute;QUIPEMENTS ET LOGICIELS</font></th>
                </tr>
                <tr>
                    <th style="width:10%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c;">Qt&eacute;</th>
                    <th style="width:50%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c;">Description</th>
                    <th style="width:20%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c;">Prix</th>
                    <th style="width:20%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c; border-right:0.5px solid #1d2e5c;">Total</th>
                </tr>
            </thead>';

foreach( $equipements as $row ) {
    $quant = $row['Qte'];
    $priceUnit = (ISSET($row['AutrePrix']) && $row['AutrePrix'] != 0) ? $row['AutrePrix'] : $row['Prix'];
    $totalEquip = $quant * $priceUnit;
    $totalAllEquip += $totalEquip;
    $html .= '<tr nobr="true">
                <td style="width:10%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c;">' . $quant . '</td>
                <td style="width:50%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c; text-align: left;">' . $row['Nom'] . '</td>
                <td style="width:20%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c; text-align: right;">' . number_format($priceUnit, 2, '.', ' ') . '<font size="-2"> $</font></td>
                <td style="width:20%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c; border-right:0.5px solid #1d2e5c; text-align: right;">' . number_format($totalEquip, 2, '.', ' ') . '<font size="-2"> $</font></td>
              </tr>';
}
$html .= '<tr>
            <td colspan="3"></td>
            <td style="width:20%; border-left:0.5px solid #1d2e5c; border-bottom:0.5px solid #1d2e5c; border-right:0.5px solid #1d2e5c; text-align: right;" bgcolor="#1d2e5c"><font color="#ffffff">' . number_format($totalAllEquip, 2, '.', ' ') . '</font><font color="#ffffff" size="-2"> $</font></td>
          </tr>
        </table>';

$pdf->writeHTML($html, true, false, false, false, '');

编辑:2016-06-01

我使用 tcpdf 库:sourceforge.net/projects/tcpdf 和 tcpdf_config.php 文件。我用来设置 header 数据的命令是:

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING, array(0,64,255), array(0,64,128));

确保设置页边距和自动分页

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

例如你可以看看 http://www.tcpdf.org/examples/example_048.phps 结果示例位于 http://www.tcpdf.org/examples/example_048.pdf

因为我设置的所有配置都不起作用(我已经像这里的示例一样设置了所有内容:http://www.tcpdf.org/examples/example_048.phps - http://www.tcpdf.org/examples/example_048.pdf),我终于设置了一个计数器来计算一个文件中的最大行数页面,然后,我添加了一个新页面,之后,我在另一页继续。

这是我找到的最简单的方法(我急于找到解决方案)

我在生成多页工资表时遇到了这个问题,我通过删除除 <table><thead><tbody>

之外的所有 HTML 标签解决了这个问题

我认为这对其他人有帮助。