简体   繁体   English

如果元素超过页面高度,dompdf 分页符?

[英]dompdf Page break if element is exceeding page height?

What is the best way to do page breaks in dompdf?在 dompdf 中进行分页的最佳方法是什么?

I have had a look here at the page-break-before css attribute, but it didn't work when I did:我在这里查看了 page-break-before css 属性,但是当我这样做时它不起作用:

table {page-break-before:auto;}

The page still breaks in the middle of my table.页面仍然在我的桌子中间断裂。

Is it possible to setup my html/css so that the page will break before the element if the element is going to exceed the page height?如果元素将超过页面高度,是否可以设置我的 html/css 以便页面会在元素之前中断?

Ideally I would like to divide my html up in to div sections so that each section will start on a new page if it is going to exceed the height of the current page.理想情况下,我想将我的 html 分成 div 部分,以便每个部分都将在新页面上开始,如果它会超过当前页面的高度。

Using page-break-inside: auto;使用page-break-inside: auto; basically says to dompdf "do what you would normally do when breaking pages."基本上是对 dompdf 说“做你通常在打破页面时会做的事情”。

To force a page break before / after your table you would use page-break-before: always;要在表格之前/之后强制分页,您可以使用page-break-before: always; / page-break-after: always; / page-break-after: always; . .

To ask dompdf to avoid breaking inside an element you would use page-break-inside: avoid;要要求 dompdf 避免在元素page-break-inside: avoid;您可以使用page-break-inside: avoid; . .

You might make quick tests with this online debugger - i finally found my pagebreak and margin issue after days of testing.您可以使用这个在线调试器进行快速测试 - 经过几天的测试,我终于发现了我的分页和边距问题。

Excursus: Did anyone install a debug environment on the development/production environment and can point me to any documentation or tutorial?附注:是否有人在开发/生产环境中安装了调试环境,并且可以向我指出任何文档或教程?

这里有一个窍门:将<table>你不希望在其他多个页面打印<table>

In my case it was happened since I have used a table inside another table.就我而言,这是因为我在另一张桌子内使用了一张桌子。 Like,像,

<table>
   <tr>
      <td>
         <table></table>
      </td>
   </tr>
 </table>

So I did was getting the table out.所以我确实把桌子拿出来了。 Solved my issue.解决了我的问题。

//Firstly assign a variable before starting for loop and set post-increment operator inside for loop. //首先在for循环开始前赋值一个变量,并在for循环内设置后增量运算符。 secondly, use with condition of data display item in a single page.其次,在单页数据显示项条件下使用。

  <?php $n=1 ?>
          @foreach ($purchases as $key=> $purchase)
               <tr >
                   <td> {{ $key + 1 }}  </td>
                   <td> {{ $purchase->supplier->company_name ? 
                   $purchase->supplier->company_name : "" }}  </td>
                   <td> {{ "S-".$purchase->id  }}   </td>
                   <td> {{  salte_items($purchase->purchaseItems) }}        </td>
                   <td> {{ $purchase->created_at->format('d-m-Y') }}  </td>
                   <td> {{ intval($purchase->total) }}    </td>
                    </tr>
                  
                    @if ( $n % 25 == 0 )
                        <div style="page-break-before:always;"> </div>
                    @endif
                    <?php $n++ ?>

           @endforeach

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

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