Guides › mPDF › mPDF configuration options

mPDF configuration options

Written for mPDF 8.2 on PHP 8.1+. Updated 2 November 2026.

Since version 7, everything you pass to mPDF goes into a single associative array given to the constructor. Unknown keys raise an exception, so typos are caught early.

$mpdf = new \Mpdf\Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4',          // or 'Letter', 'A4-L' for landscape, or [width, height] in mm
    'orientation' => 'P',      // 'P' portrait, 'L' landscape
    'margin_left' => 15,
    'margin_right' => 15,
    'margin_top' => 20,
    'margin_bottom' => 20,
    'margin_header' => 8,      // distance from the page edge to the header
    'margin_footer' => 8,
    'default_font_size' => 10,
    'default_font' => 'dejavusans',
    'tempDir' => sys_get_temp_dir() . '/mpdf',
]);

Margins are in millimetres. The top and bottom margins must leave room for any header or footer, or the body text will run underneath them.

The settings you’ll use most

Key What it does
format Paper size name (A4, A5, Letter, Legal) or [w, h] in mm. Add -L for landscape.
orientation P or L.
margin_* Page margins, plus margin_header and margin_footer.
default_font Font for text with no font-family. Use a key from the font config, such as dejavusans.
mode utf-8 for most work. c uses only the PDF core fonts: smaller files, but Latin-1 text only.
tempDir Writable folder for caches. Always set it in production.
fontDir, fontdata Add your own fonts (see fonts and languages).
autoScriptToLang, autoLangToFont Pick suitable fonts for mixed-language text automatically.
img_dpi Resolution assumed for images with no size set (see images).

Changing settings after construction

Some options are plain properties that you can set afterwards:

$mpdf->SetDisplayMode('fullpage');   // how viewers open the file
$mpdf->shrink_tables_to_fit = 1;     // don't shrink wide tables

Page size and margins can also change mid-document with AddPage() or <pagebreak> attributes. See page breaks.

Old constructor arguments

mPDF 6 used new mPDF($mode, $format, $default_font_size, $default_font, $margin_left, $margin_right, $margin_top, $margin_bottom, $margin_header, $margin_footer, $orientation). Each positional argument is now the array key of the same name, so new mPDF('utf-8', 'A4-L', 0, '', 10, 10, 10, 10) becomes:

$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4-L', 'margin_left' => 10, 'margin_right' => 10, 'margin_top' => 10, 'margin_bottom' => 10]);

The full list of keys is in the official documentation at mpdf.github.io.