mPDF Manual – Tables

Table layout

mPDF will atempt to layout tables using the same algorithm recommended by the HTML specifications (see Auto-layout algorithm). However, the constraints of fitting content to the page size means that the recommended algorithm has to be altered.

In general, mPDF places more priority on producing a pleasing, efficiently laid out table than it does on respecting defined values e.g. <table width=”300px”> or <td width=”30%”>

If the result is not what you want, consider using some of the following to control the layout:

  • change the maximum shrinkage factor allowed for an individual table e.g. <table autosize="1.6">
  • prevent an individual table from resizing e.g. <table autosize="1">
  • prevent all tables from resizing: $mpdf->shrink_tables_to_fit=1;
  • non-breaking spaces &nbsp;
  • <td nowrap="nowrap">
  • <td style="white-space:nowrap">
  • <td style="width: 33%">
  • <td style="width: 5cm">
  • <table style="page-break-inside:avoid"> to force the table onto one page.
  • <table style="overflow: visible|hidden|wrap"> to control wide tables or tables with specific widths specified

Overriding the Auto- Layout

Other methods to override the default layout algorithm.

$keep_table_proportions

If the table width is set greater than the page width allows, mPDF will by default ignore any defined sizes and attempt to auto-layout the table to the page width. This will result in relative column widths etc. being lost.

If you wish to maintain the relative proportions of the table, set $keep_table_proportions = TRUE; this forces the table to be resized, but keep relative proportions. NB It also forces respect of cell widths set by %

$ignore_table_percents

Table and cell widths set as a percent value are respected when possible by mPDF - as long as the table layout meets the other constraints. This can lead to an ugly or inefficiently laid out table for a printed document. Setting $$ignore_table_percents = TRUE; will force mPDF to ignore any table or cell widths set as percent values.

$ignore_table_width

Table widths set as absolute length values are respected when possible by mPDF - as long as the table layout meets the other constraints. This can lead to an ugly or inefficiently laid out table for a printed document. Setting $$ignore_table_$width = TRUE; will force mPDF to ignore any table widths set as absolute length values.

$tableMinSizePriority

If there is a conflict between respecting $page-break-inside:avoid and respecting the maximum value allowed for $autosize, the configurable variable tableMinSizePriority will determine which factor takes priority. (mPDF v>=4.6)