在dompdf中使用分页符时如何解决设计中断

How to solve design break when use page-break in dompdf

在第 3 行之后使用分页符生成 pdf 时,设计会崩溃。这是我的代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>DOM-PDF</title>
  </head>
  <body>
    <table style="width:100%;">
        <thead>
            <tr>
                <th>Serial</th>
                <th>Name</th>
                <th>Roll</th>
                <th>Info</th>
            </tr>
        </thead>
        <tbody>
        @php
        $n = 0;
        for($i=0;$i<10;$i++){
        @endphp
            <tr style="text-align:center;">
                <td>1</td>
                <td>Rashedul Hasan</td>
                <td>1208039</td>
                <td>I am an employee.</td>
            </tr>
        
        @php
        if($n==3){
        echo "<i style='page-break-before:always;'></i> ";
        }
        $n++;
        }
        @endphp
        </tbody>
    </table>
  </body>
</html>

这是第 1 页的 pdf 视图

这是第 2 页的 pdf 视图

第 2 页第二行向右移动。如何解决?

使用 chunks 而不是破坏 table 怎么样?

{{-- Replace collect()->times(10) with a collection when you're getting the actual data from DB --}}
@foreach (collect()->times(10)->chunk(3) as $chunk)
    <table style="width:100%;">
        <thead>
            <tr>
                <th>Serial</th>
                <th>Name</th>
                <th>Roll</th>
                <th>Info</th>
            </tr>
        </thead>
        <tbody>
            @foreach($chunk as $result)
                <tr style="text-align:center;">
                    <td>{{ $result }}</td>
                    <td>Rashedul Hasan</td>
                    <td>1208039</td>
                    <td>I am an employee.</td>
                </tr>        
            @endforeach
        </tbody>
    </table>
    <i style='page-break-before:always;'></i>
@endforeach