mPDF Manual – mPDF functions


(mPDF ≥ 2.3)

SetDocTemplate – Specify an external PDF file to use as a template


void SetDocTemplate ( [ string $file [, boolean $continue ]])

Specify an external PDF file to use as a template. Each page of the external source PDF file will be used as a template for the corresponding page in your new document. If the current mPDF document has more pages than the external PDF source document, the last page will (optionally) continue to be used for any remaining pages.



This parameter specifies the source PDF file used as the template document.  $file should be a relative path to a local file.

Default: BLANK


Values: 1 | 0 | true | false

If true (or any positive value) it forces the last page of the source file to continue to be used as a template, if the current mPDF document contains more pages than the source file.

Default: false


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


// Do not add page until doc template set, as it is inserted at the start of each page
$mpdf->WriteHTML('Hello World');

// Subsequent pages from logoheader.pdf will be inserted on all subsequent pages

See Also

Fork me on GitHub