【问题标题】:dompdf is not rendering Table from html in laraveldompdf 没有在 laravel 中从 html 呈现表格
【发布时间】:2018-08-24 17:11:45
【问题描述】:

我在我的 laravel 项目中使用 dompdf。 我正在尝试生成包含表格的 PDF。表格的所有数据正在生成,但表格边框未显示。

但是当我在浏览器中生成 html 时,它在表格的 100% 宽度下正常工作,但在 PDF 中没有得到 100% 的宽度。

我的控制器代码:

    $users  = $course->users()
                        ->withPivot('section_id')
                        ->wherePivot('section_id', '=', $section->id)
                        ->orderBy('student_id', 'asc')
                        ->get();

    $season = Season::where('is_ended', 0)->first();

    $pdf = PDF::loadView('sections.attendace', compact('users', 'course', 'season', 'section'));

    return $pdf->stream('attendance.pdf');

刀片代码:

        <div class="attendance-table">

            <table class="table-bordered">

                <tr>
                    <th class="attendance-cell">ID</th>
                    <th class="attendance-cell">Name</th>
                    @for($i = 1; $i<=9; $i++)
                        <th class="blank-cell attendance-cell">{{$i}}</th>
                    @endfor
                </tr>

                @foreach($users as $user)
                    <tr>
                        <td class="attendance-cell">{{$user->student_id}}</td>
                        <td class="attendance-cell">{{ucwords($user->name)}}</td>
                        @for($i = 1; $i<=9; $i++)
                            <td class="blank-cell attendance-cell">{{$i}}</td>
                        @endfor
                    </tr>
                @endforeach

            </table>

        </div>

CSS

.attendance-table table{
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #000;
}

.blank-cell{

  min-width: 50px;


}

.attendance-cell{

  padding: 8px;


}

.attendance-table table th.attendance-cell, .attendance-table table td.attendance-cell {
    border: 1px solid #000;
}

生成的 PDF

生成的 HTML

现在,如何获得边框以及如何获得 100% 的表格宽度?

【问题讨论】:

  • dompdf 表格确实会带来一些麻烦。您可以在 px 中指定 ~~700px 来表示纵向 A4,而不是 100%。对于边框,尝试添加此样式进行测试,td,th{border:1px solid black}
  • 试过了。但没有帮助! :(

标签: laravel dompdf


【解决方案1】:

我也遇到了同样的问题,所以我将 CSS 放在刀片本身的 &lt;style&gt; 标记中。

DOMPDF 不会从 .css 文件中提取。

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 2021-03-10
    • 2010-10-31
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    相关资源
    最近更新 更多