mPDF Manual – mPDF functions


(mPDF ≥ 2.3)

SetPageTemplate – Specify a page from an external PDF file to use as a template


void SetPageTemplate ([ int $templateID ])

Specify a page from an external PDF file to use as a template. The page must have already been stored as a ‘template’ using SetSourceFile(). Once a ‘page template’ has been set, the template is inserted on every subsequent page of the document. The template is added to the page at the same time as a new page is started (in the Header).



This parameter specifies the ID of the page template to use. Value must be a valid template ID from SetSourceFile().

Default or BLANK will clear the template, so subsequent pages will not have the template added.


Version Description
2.3 Function was added.


Example #1


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

$mpdf = new \Mpdf\Mpdf();
$mpdf->SetImportUse(); // only with mPDF <8.0

$pagecount = $mpdf->SetSourceFile('logoheader.pdf');
$tplId = $mpdf->ImportPage($pagecount);

// Do not add page until page template set, as it is inserted at the start of each page

$mpdf->WriteHTML('Hello World');

// The template $tplId will be inserted on all subsequent pages until (optionally)
// $mpdf->SetPageTemplate();


See Also

Fork me on GitHub