<table>some random content </table>
<div style="page-break-before:always"> </div>
<div>some random content </div>
Hello everyone,
I’m currently using the code snippet above in an attempt to separate my table and the div element onto two separate pages when generating a PDF. However, it appears that is not functioning as expected, and both the table and the div remain on the same page. I’ve also experimented with the CSS style and , but encountered the same issue.
Tried Solution:
<div style="break-before:always"> </div>
<div style="break-before:page"> </div>
<div style="page-break-before:page"> </div>
<div style="page-break-before:always"> </div>
- CSS Style
I would appreciate any insights into the potential issues or solutions for achieving the desired page separation. Thank you!
2
Answers
The page-break-before CSS property doesn’t work on elements or most block-level elements when it comes to generating PDFs. It’s primarily intended for controlling page breaks when printing web pages, and its behavior can be inconsistent when it comes to PDF generation.
If you want to ensure that your table and the following appear on separate pages in a PDF, you can use a different approach. One commonly used method is to wrap each section in a with a specific class and then apply a CSS rule to force page breaks before those classes. Here’s an example:
And in your CSS:
The
page-break-before
CSS property may not be supported by all browsers or PDF viewers. It is important to note that the behavior of page breaks can vary across different rendering engines and environments. You can try using different ways like adjusting margins, usingpage-break-inside
, or using a different method for generating PDFs to achieve the desired page break behavior.