mPDF Manual – Paging

Different page sizes

(mPDF ≥ 4.3)

The page (sheet) size can be reset within the document.

There are different ways to change sheet size:

1) Using CSS @page

CSS with @page selectors:

<style>

@page { sheet-size: A3-L; }

@page bigger { sheet-size: 420mm 370mm; }

@page toc { sheet-size: A4; }

h1.bigsection {
        page-break-before: always;
        page: bigger;
}

</style>

You can reference the @page selectors using other CSS as above (and see Using @page) or setting attributes in:

  • <tocpagebreak> e.g. <tocpagebreak ... page-selector="bigger" toc-page-selector="toc" ... />
  • <pagebreak>  e.g. <pagebreak ... page-selector="bigger" ... />

The functions AddPageByArray() and TOCpagebreak() both have parameters which allow you to select a @page.

2) Specify the sheet size when forcing a new page (HTML tags)
  • <pagebreak> e.g. <pagebreak ... sheet-size="A3-L" ... />
  • <tocpagebreak> e.g. <tocpagebreak ... sheet-size="420mm 370mm" toc-sheet-size="A4" ... />

Accepted values are:

  • "A4", "A3", "Letter" etc
  • "A4-L", "A3-L", "Letter-L" etc. for landscape
  • a string of 2 dimensions e.g. "21cm 29.7cm" Can be px, pt, in, mm, cm: but not em, ex or %
3) Specify the sheet size when forcing a new page (functions)

The functions AddPageByArray() (or AddPage()) and TOCpagebreak() both have parameters to select sheet size.

Accepted values - same options as the original \Mpdf\Mpdf::__construct() - are:

  • "A4", "A3", "Letter" etc
  • "A4-L", "A3-L", "Letter-L" etc. for landscape
  • an array of 2 numbers which are the width then height in mm e.g. array(210, 297)

Limitations

  • mPDF will not carry block-style elements across page-breaks.
  • Does not work with < formfeed>, and disabled if using $this->restoreBlockPageBreaks
  • Cannot use @page { size: portrait|landscape; } at the same time as defining the sheet-size
Fork me on GitHub