DomPDF不能很好地渲染表格

RK.*_*RK. 14 php pdf codeigniter dompdf

我试图使用DomPDF获取PDF,但我遇到了一个奇怪的问题.所有数据和其他东西都很好但是当它以PDF格式呈现时,表格的第一行总是不合时宜.首先,我可能是表格正在下一页导致风格脱离上下文但我试图将表限制为一页,并发现问题仍然存在.所以,每一页上的第一行表都很疯狂.以下是我的PDF代码和屏幕截图.

调节器

$dompdf = new DOMPDF();
$dompdf->load_html($listing);
$dompdf->set_paper('a4', 'landscape');
$dompdf->render();
$dompdf->stream("sample.pdf");
Run Code Online (Sandbox Code Playgroud)

视图

<table class="table table-bordered">
    <tr>
        <th width="150">Client </th>
        <td>Client Name </td>
    </tr>

    <tr>
        <th>Site </th>
        <td><?php print $site->title; ?></td>
    </tr>

    <tr>
        <th>Address </th>
        <td>
            <?php 
                print $site->unit.' '.
                $site->street.' '.
                $site->suburb.' '.
                $site->state.' '.
                $site->location; 
            ?>
        </td>
    </tr>

    <tr>
        <th>Post Code </th>
        <td><?php print $site->postcode; ?></td>
    </tr>
    <tr>
        <th colspan="2"> Site Information</th>
    </tr>
    <tr>
        <td colspan="2" height="150"> <?php print $site->site_information; ?></td>
    </tr>
    <tr>
        <th colspan="2">Work Instruction</th>
    </tr>
    <tr>
        <td colspan="2" height="200"> <?php print $site->work_instruction; ?></td>
    </tr>
    <tr>
        <th colspan="2">Equipment on Site</th>
    </tr>
    <tr>
        <td colspan="2"> <?php print $site->site_equipment; ?></td>
    </tr>
    <tr>
        <th colspan="2">Special Instructions</th>
    </tr>
    <tr>
        <td colspan="2" height="100"> <?php print $site->special_instruction; ?></td>
    </tr>
    <tr>
        <th>Contact Person </th>
        <td><?php print $site->contact_person; ?></td>
    </tr>
    <tr>
        <th>Contact Number </th>
        <td><?php print $site->contact_no; ?></td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

第1页: 在此输入图像描述

第2页: 在此输入图像描述

任何帮助将受到高度赞赏.谢谢

小智 19

我用

thead:before, thead:after { display: none; }
tbody:before, tbody:after { display: none; }
Run Code Online (Sandbox Code Playgroud)


Bri*_*anS 11

几乎可以肯定,问题是你使用Bootstrap.很多与Bootstrap相关的dompdf问题都与:before/ :afterdeclarations有关.我认为你可以通过对dompdf应用以下CSS来解决这个特殊情况下的问题:

tbody:before, tbody:after { display: none; }
Run Code Online (Sandbox Code Playgroud)