dompdf Page break if element is exceeding page height?
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.
Related videos on Youtube
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, 2022Comments
-
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 over 10 yearsor place it into <div>
-
andreas-supersmart over 9 years
page-break-inside:avoid;
made disappear images in table and has an issue especiall when usingcolspan=2
in my case -
Fr0zenFyr almost 9 yearsMakes 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 over 8 yearsJust a heads-up: I tried using the
page-break-inside: avoid
on<tbody/>
and<table/>
tags, as well as usingpage-break-after: avoid
on a<tr/>
– both gave me some extra empty pages. My solution was to wrap the tables in a<div/>
withpage-break-inside: avoid
applied. -
steinkel over 7 yearsnote this was not working with rowspan in tds, I finally switched to mpdf because it was a very simple (but long) table
-
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 over 4 yearsThis 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 almost 4 yearsThanks for that debugger link, it's very useful.
-
phoenixstudio over 3 yearsPlease add comments and explain your code
-
phoenixstudio over 3 yearsyou can add your comment to your code by editing your answer