dompdf Page break if element is exceeding page hei

2020-02-17 00:23发布

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 {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?

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.

4条回答
别忘想泡老子
2楼-- · 2020-02-17 00: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;.

查看更多
时光不老,我们不散
3楼-- · 2020-02-17 01:01

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

查看更多
Emotional °昔
4楼-- · 2020-02-17 01:12

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.

查看更多
迷人小祖宗
5楼-- · 2020-02-17 01:13

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?

查看更多
登录 后发表回答