简体   繁体   English

DomPDF不能很好地渲染表格

[英]DomPDF does not render table nicely

I am trying to get PDF using DomPDF but I come cross a strange problem. 我试图使用DomPDF获取PDF,但我遇到了一个奇怪的问题。 All the data and other things are fine but when it renders in PDF the first line of the table is always out of style. 所有数据和其他东西都很好但是当它以PDF格式呈现时,表格的第一行总是不合时宜。 Firstly, I though may be table is going to the next page which cause style out of context but I tried to limit table to one page and found out that the problem still exists. 首先,我可能是表格正在下一页导致风格脱离上下文但我试图将表限制为一页,并发现问题仍然存在。 So, the first row of table on every page goes crazy. 所以,每一页上的第一行表都很疯狂。 Following is my code and screen shots of PDF. 以下是我的PDF代码和屏幕截图。

Controller 调节器

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

View 视图

<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>

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

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

Any help will be highly appreciated. 任何帮助将受到高度赞赏。 Thanks 谢谢

I use 我用

thead:before, thead:after { display: none; }
tbody:before, tbody:after { display: none; }

Almost certainly the issue is your use of Bootstrap. 几乎可以肯定,问题是你使用Bootstrap。 A lot of dompdf issues related to Bootstrap have to do with the :before / :after declarations. 很多与Bootstrap相关的dompdf问题都与:before / :after声明有关。 I think you can work around the problem in this particular case by applying the following CSS for dompdf: 我认为你可以通过对dompdf应用以下CSS来解决这个特殊情况下的问题:

tbody:before, tbody:after { display: none; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM