dompdf Page break if element is exceeding page height?

93,489

Solution 1

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;.

Solution 2

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?

Solution 3

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

Solution 4

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.

Share:
93,489

Related videos on Youtube

startupsmith
Author by

startupsmith

Software developer. Currently working with C# on Mono, Silverstripe, Mono for Android and Monotouch. I have also done a lot of work deploying servers to the cloud (EC2 and Rackspace).

Updated on July 09, 2022

Comments

  • startupsmith
    startupsmith almost 2 years

    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.

  • Paktas
    Paktas over 10 years
    or place it into <div>
  • andreas-supersmart
    andreas-supersmart over 9 years
    page-break-inside:avoid; made disappear images in table and has an issue especiall when using colspan=2 in my case
  • Fr0zenFyr
    Fr0zenFyr almost 9 years
    Makes sense checking the possible issues on this debugger. For example, a small change in CSS can affect big. Especially, the dompdflog tab is very handy.
  • mehov
    mehov over 8 years
    Just a heads-up: I tried using the page-break-inside: avoid on <tbody/> and <table/> tags, as well as using page-break-after: avoid on a <tr/> – both gave me some extra empty pages. My solution was to wrap the tables in a <div/> with page-break-inside: avoid applied.
  • steinkel
    steinkel over 7 years
    note this was not working with rowspan in tds, I finally switched to mpdf because it was a very simple (but long) table
  • TOPKAT
    TOPKAT over 6 years
    page-break-inside: auto; doesn't work with elements larger than the pages UNFORTUNATELY...see: github.com/dompdf/dompdf/issues/653 and github.com/dompdf/dompdf/issues/809
  • kenef
    kenef over 4 years
    This is still a valid fix. I was unable to get my large table converted to PDF without cutting off content past the first page. The css rule page-break-after: always; Saved my but. I just add that rule inline every time the content gets close to the page height. Big thanks for this little trick!
  • JoshGeake
    JoshGeake almost 4 years
    Thanks for that debugger link, it's very useful.
  • phoenixstudio
    phoenixstudio over 3 years
    Please add comments and explain your code
  • phoenixstudio
    phoenixstudio over 3 years
    you can add your comment to your code by editing your answer