dompdf Page break if element is exceeding page height?

后端 未结 5 1615
清酒与你
清酒与你 2021-01-30 16:46

What is the best way to do page breaks in dompdf?

I have had a look here at the page-break-before css attribute, but it didn\'t work when I did:

table {p         


        
相关标签:
5条回答
  • 2021-01-30 16:59

    Using page-break-inside: auto; basically says to dompdf "do what you would normally do when breaking pages."

    To force a page break before / after your table you would use page-break-before: always; / page-break-after: always;.

    To ask dompdf to avoid breaking inside an element you would use page-break-inside: avoid;.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-30 17:05

    Here's a trick: place the <table> you do NOT want to print across multiple pages in another <table>.

    0 讨论(0)
  • 2021-01-30 17:10

    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?

    0 讨论(0)
  • 2021-01-30 17:23

    //Firstly assign a variable before starting for loop and set post-increment operator inside for loop. 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
    
    0 讨论(0)
提交回复
热议问题