mPDF Manual – mPDF functions

ImportPage() (until 8.0)

(mPDF ≥ 2.3 && mPDF < 8.0)

ImportPage – Import a page from an external PDF file

Description

int ImportPage ( int $pageno [, float $crop_x [, float $crop_y [, float $crop_w [, float $crop_h [, string $boxname ]]]]])

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

$pageno

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

Default: 1

$crop_x

Specifies the x-coordinate (abscissa) for the page of the source PDF file, when importing a ‘cropped’ page into the template. Value in millimetres.

Default: 0

$crop_y

Specifies the y-coordinate (ordinate) for the page of the source PDF file, when importing a ‘cropped’ page into the template. Value in millimetres.

Default: 0

$crop_w

Specifies the width in millimetres when importing a ‘cropped’ page into the template.

Default: null uses the full page width from the source file

$crop_h

Specifies the height in millimetres when importing a ‘cropped’ page into the template.

Default: null uses the full page height from the source file

$boxname

$boxname is currently not used.

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
2.3 Function was added.

Examples

Example #1 - Using a full page

<?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->UseTemplate($tplId);

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

$mpdf->Output();

Changelog

Version Description
8.0 Function was replaced by importPage().

Example #2 - Using a ‘cropped’ page

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

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

$pagecount = $mpdf->SetSourceFile('testfile.pdf');
$tplId = $mpdf->ImportPage($pagecount, 50, 50, 100, 100);

$mpdf->UseTemplate($tplId, '', '', 100, 100);

$mpdf->Output();

See Also

Fork me on GitHub