mPDF Manual – mPDF functions

importPage() (since 8.0)

(mPDF ≥ 8.0)

importPage – Import a page from an external PDF file


int importPage ( int $pageNumber [, string $box [, bool $groupXObject ]]])

Import a page, or part of a page, from an external PDF file. The external source file must first be set with setSourceFile(). A ‘template’ is created in mPDF which stores the image of this page, ready to insert into the document.



This parameter specifies the page number from the source PDF file to import.  $pageNumber should be a positive integer value.

Default: 1


The page boundary to import. Default set to \setasign\Fpdi\PdfReader\PageBoundaries::CROP_BOX.

Default: \setasign\Fpdi\PdfReader\PageBoundaries::CROP_BOX


Define the form XObject as a group XObject to support transparency (if used).

Default: true

Return Value

importPage() returns an ID for the template which it has created. This ID can be used at any time to insert the template into the document with useTemplate() or SetPageTemplate()


Version Description
8.0 Function was added.


Example #1 - Using a full page


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

$mpdf = new \Mpdf\Mpdf();

$pagecount = $mpdf->setSourceFile('logoheader.pdf');
$tplId = $mpdf->importPage($pagecount);

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


Example #2 - Using a ‘cropped’ page

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

$mpdf = new \Mpdf\Mpdf();

$pagecount = $mpdf->setSourceFile('testfile.pdf');
$tplId = $mpdf->importPage($pagecount);

$mpdf->useTemplate($tplId, 50, 50, 100, 100);


See Also

Fork me on GitHub