TCPDF:自动分页后图像与 html 表格标题重叠

TCPDF: Image overlaps html table header after auto-page-break

提问人:root66 提问时间:8/7/2015 最后编辑:root66 更新时间:8/7/2015 访问量:1874

问:

以下代码输出一个表,该表具有两行高的表头,每行中都有一个测试图像。当有自动分页符时,图像将正确打印在下一页上,但它会与某些像素的表头重叠(见屏幕截图)。下一行中的图像位置再次正确。第二个表头文本也丢失了!

问题在于多行表标题。使用一行只能解决问题,但就我而言,我需要多个表标题行。

enter image description here

您知道解决此问题的解决方法(最新的 TCPDF 6.2.11)吗?

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

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

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

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

$pdf->AddPage();

$pdf->SetFont('helvetica', '', 8);

$tbl = '
        <style>
            th {
                background-color: #cccccc;
                font-weight: bold;
            }
        </style>

        <table width="100%" cellpadding="2" cellspacing="0" border="1">
        <thead>
            <tr>
                <th>TH1</th>
            </tr>
            <tr>
                <th>TH2</th>
            </tr>
        </thead>';
for($i = 0; $i < 10; $i++)
$tbl .= '   
        <tr>
            <td><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/A_butterfly_feeding_on_the_tears_of_a_turtle_in_Ecuador.jpg/320px-A_butterfly_feeding_on_the_tears_of_a_turtle_in_Ecuador.jpg" width="100" height="100"></td>
        </tr>';
$tbl .='</table>';

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

$pdf->Output('example.pdf', 'I');
PHP 的TCPDF格式

评论


答:

0赞 Abdelilah Aassou 8/7/2015 #1

删除 thead 标签,并为您的第 2 个使用一个 tr 标签,而不是为每个第 2 个使用 tr 标签

<tr>
 <th></th>
 <th></th>
</tr>

评论

0赞 root66 8/7/2015
这只是一个简单的例子。就我而言,我确实需要两条表头行。