首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在dompdf中使用分页符时如何解决设计中断

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

Stack Overflow用户
提问于 2020-12-24 22:43:11
回答 1查看 46关注 0票数 0

当生成pdf时,在第3行之后使用page-break-pdf,设计被分解了。以下是我的代码

代码语言:javascript
复制
<!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视图

在第二页,第二行向右移动。如何修复它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-24 22:54:55

如果使用chunks而不是打破常规呢?

代码语言:javascript
复制
{{-- 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65439799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档