mPDF Manual – mPDF functions


(mPDF >= 5.0)

mPDF – Initialise an instance of mPDF class


class mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])

Initialise an instance of mPDF class.



This parameter specifies the mode of the new document.


Codepage Values (case-insensitive)




“…-s” or “s”

“…+aCJK” or “+aCJK”

“…-aCJK” or “-aCJK”

where … can be any string. Only language/country codes will have any effect, but other strings are parsed for backwards compatability (but have no effect).

Only some combinations make sense. See Choosing a configuration for more details.

Country/Language code values (case-insensitive)

Country/language codes are defined in config_cp.php

A country/language code can be passed as e.g. “en-GB” or “en_GB” or “en”***




$format can be specified either as a pre-defined page size, or as an array of width and height in millimetres (see Example #2 below).


Values (case-insensitive)

A0 - A10, B0 - B10, C0 - C10

4A0, 2A0, RA0 - RA4, SRA0 - SRA4

Letter, Legal, Executive, Folio

Demy, Royal

A (Type A paperback 111x178mm)

B (Type B paperback 128x198mm)

Ledger, Tabloid*

All of the above values can be suffixed with “-L” to force a Landscape page orientation document e.g. “A4-L”.

If $format is defined as a string, the final $orientation parameter will be ignored.

*Ledger and Tabloid are standard formats with the same page size but different orientation (Ledger is landscape, and Tabloid is portrait). mPDF treats these identically; if you wish to use Ledger, you should specify “Ledger-L” for landscape.


Sets the default document font size in points (pt)

BLANK or omitted or 0 uses the default value set in $defaultCSS.



Sets the default font-family for the new document.

BLANK or omitted uses default value set in $defaultCSS unless $codepage has been set to “win-1252”. If $codepage=”win-1252”, the appropriate core Adobe font will be set i.e. Helvetica, Times, or Courier.







Sets the page margins for the new document.

All values should be specified as LENGTH in millimetres.

If you are creating a DOUBLE-SIDED document, the margin values specified will be used for ODD pages; left and right margins will be mirrored for EVEN pages.

BLANK or omitted uses the default values.


$margin_left 15

$margin_right 15

$margin_top 16

$margin_bottom 16

$margin_header 9

$margin_footer 9



This attribute specifies the default page orientation of the new document if $format is defined as an array. This value will be ignored if $format is a string value.


Values (case-insensitive)

P: DEFAULT Portrait

L: Landscape


2.0 The $orientation parameter was added.
5.0 The $mode parameter renamed (from $codepage), and recognised values changed


Example #1


// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new mPDF();

Hallo World




Example #2


// Define a new mPDF document using utf-8 fonts

$mpdf = new mPDF('utf-8');

// Define a new mPDF document using win-1252 fonts based on a language/country code

$mpdf = new mPDF('en-GB');

// Define a Landscape page size/format by name

$mpdf = new mPDF('utf-8', 'A4-L');

// Define a page size/format by array - page will be 190mm wide x 236mm height

$mpdf = new mPDF('utf-8', array(190,236));

// Define a page using all default values except "L" for Landscape orientation

$mpdf = new mPDF('','', 0, '', 15, 15, 16, 16, 9, 9, 'L');


See Also