Search code examples
phpcssdompdf

How to display the large table without breaking in the dompdf while Generating the Pdf


I have Generated the PDF file for the For the Following table using the DOMPDF. But while generating the pdf its only showing the First 15 rows of the table.

Note: I have used the style in tables page-break-inside: avoid;

i have attached the HTML coding of the table in the fiddle.

https://jsfiddle.net/o4ga8uze/


Solution

  • In relation to your document the main advice I can give is to get rid of the wrapper table. If any particular table cell exceeds the page size you'll run into a fairly nasty bug. Luckily for your document you do not need that outer table since all it's doing is wrapping your actual content to provide spacing.

    Instead of this:

    <table align="left" cellpadding="0" cellspacing="0" style="margin:5px;  page-break-inside: avoid;" width="100%">
      <tr>
        <th class="head">Heading</th>
      </tr>
      <tr>
        <td style="border:1px solid; page-break-inside: avoid;" class="border-top border-left border-right border-bottom">
          <!-- invoice table -->
        </td>
      </tr>
    </table>
    

    Try this:

    <div style="margin:5px;">
      <div class="head">Heading</div>
      <div style="border:1px solid;" class="border-top border-left border-right border-bottom">
        <!-- invoice table -->
      </div>
    </div>
    

    I updated your fiddle: https://jsfiddle.net/o4ga8uze/1/

    As far as preventing the table from paging... You don't include an actual reference to all your stylesheets so it's difficult to provide much guidance. The first thing I can say is that since your table is all that's on the page (at least in your sample) it would have to have a low enough number of rows to not require paging.

    I notice that your reference Bootstrap 2.3.2 so I'll also note that dompdf doesn't work all that well with bootstrap at this time. You might try setting a high enough DPI such that dompdf is able to fit more of the content on the page.

    • In v0.6.2 or earlier set the DOMPDF_DPI configuration constant to, for example, 300.
    • In v0.7.0 set the option after instantiating dompdf: $dompdf->set_option('dpi', 300);

    Finally, drop the page-break-inside: avoid; styling. This can be particularly problematic with content that exceeds the page size, particularly tables.