【问题标题】:TCPDF: Image overlaps html table header after auto-page-breakTCPDF:自动分页后图像与 html 表头重叠
【发布时间】:2015-08-06 16:45:30
【问题描述】:

以下代码输出一个表格,表格标题有两行高,每行有一个测试图像。当出现自动分页时,图像将正确打印在下一页上,但它会与表格标题重叠一些像素(见屏幕截图)。下一行的图像位置再次正确。第二个表头文字也不见了!

问题是多行表格标题。使用一行只能解决问题,但在我的情况下我需要多个表头行。

您知道解决此问题的解决方法吗(最新的 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


    【解决方案1】:

    删除thead标签并为你的第二个使用一个tr标签,而不是为每个th使用一个tr

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

    【讨论】:

    • 这只是一个简单的例子。在我的情况下,我确实需要两条表格标题行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-14
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    相关资源
    最近更新 更多