mPDF Manual – mPDF functions

ImportPage()

(mPDF >= 2.3)

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

VersionDescription
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->SetImportUse();

$pagecount = $mpdf->SetSourceFile('logoheader.pdf');

$tplId = $mpdf->ImportPage($pagecount);

$mpdf->UseTemplate($tplId);

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

$mpdf->Output();

Example #2 - Using a ‘cropped’ page

<?php

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

$mpdf = new mPDF();

$mpdf->SetImportUse();

$pagecount = $mpdf->SetSourceFile('testfile.pdf');

$tplId = $mpdf->ImportPage($pagecount, 50, 50, 100, 100);

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

$mpdf->Output();

?>

See Also