dompdf 未从 laravel 中的 html 渲染 Table

dompdf is not rendering Table from html in laravel

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

但是当我在浏览器中生成 html 时,它在 table 的 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');

Blade代码:

        <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

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

我也有同样的问题,所以我把 CSS 放在 blade 本身的 <style> 标签里。

DOMPDF 不从 .css 文件中提取。

希望对您有所帮助!