mPDF Manual – mPDF functions

importPage() (since 8.0)

(mPDF ≥ 8.0)

importPage – Import a page from an external PDF file

Description

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.

Parameters

$pageNumber

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

Default: 1

$box

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

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

$groupXObject

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

Changelog

Version Description
8.0 Function was added.

Examples

Example #1 - Using a full page

<?php

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

$mpdf = new \Mpdf\Mpdf();

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

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

$mpdf->Output();

Example #2 - Using a ‘cropped’ page

<?php
// 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);

$mpdf->Output();

See Also

Fork me on GitHub