dompdf - start tr in new page

10,903

Solution 1

May be following 2 possibility helps you.

1)If you are using this in for loop or while loop then in first page u can use count in your loop means only some count that data will display after that another page will display but before start another page use Following code.

 <div style="page-break-after:always;"></div> 

By using this code page will break and start from another new page.

2) If you are using simple table tr td tags without any loop than just simply after some tr tag close table and us above page break code and start form remaining tr tag.

Solution 2

Ideally you would use orphans and widows for this kind of thing. Unfortunately that's not supported by dompdf as of this answer.

1) If "Heading" is truly a heading then place it in a thead section. The main thing to remember about this is that it will propagate to all the pages that the body of the table occupies. Though there are some peculiarities about how dompdf handles this when you only have one body row.

<table>
  <thead>
    <tr><th align="left"><b>Heading</b></td></tr>
  </thead>
  <tbody>
    <tr><td>
      <table width="95%" align="center" cellspacing="2" cellpadding="2" style=""><tr><td>
        <font size="14px" face="Verdana">content</font>
      </td></tr></table>
    </td></tr>
  </tbody>
</table>

2) Style your header row with page-break-after: avoid;. Unfortunately this doesn't really work the way it should right now in dompdf.

<table>
  <tr style="page-break-after: avoid;"><th align="left"><b>Heading</b></td></tr>
  <tr><td>
    <table width="95%" align="center" cellspacing="2" cellpadding="2" style=""><tr><td>
      <font size="14px" face="Verdana">content</font>
    </td></tr></table>
  </td></tr>
</table>

3) Don't use tables, dompdf actually does much better with this.

<div>
  <div style="page-break-after: avoid;"><b>Heading</b></div>
  <div style="page-break-before: avoid; width: 95%; margin: auto;">
      <font size="14px" face="Verdana">content</font>
  </div>
</div>

(I'm basing this last one on the sample HTML you provided. If this isn't actually your use case then build out your sample code a bit more so we know what you're trying to achieve.)

Share:
10,903
Ripa Saha
Author by

Ripa Saha

My portfolio:- https://clusterphase.wixsite.com/ripasaha

Updated on June 14, 2022

Comments

  • Ripa Saha
    Ripa Saha almost 2 years

    I'm using dompdf for creating pdf.

    Here I've below requirement:-

    I need to open an new page if there is only 1 line remaining in the previous page.

    The example tr is below:-

    <tr><td align="left"><b>Heading</b></td></tr>
    <tr><td><table width="95%" align="center" cellspacing="2" cellpadding="2" style="">
    <tr><td><font size="14px" face="Verdana">content</font></td></tr>
    </table></td></tr>
    

    The purpose of this requirement is - HEADING and start of CONTENT will be in same page. Sometime HEADING is coming in a page and CONTENT is starting from next page.

    I need an solution of this situation.

    Does anybody have any idea?