mPDF Manual – mPDF functions

SetPageTemplate()

(mPDF ≥ 2.3)

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

Description

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).

Parameters

$templateID

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.

Changelog

Version Description
2.3 Function was added.

Examples

Example #1

<?php

// 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);
$mpdf->SetPageTemplate($tplId);

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

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

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

$mpdf->Output();

See Also

Fork me on GitHub