(mPDF ≥ 2.3 && mPDF < 8.0)
ImportPage – Import a page from an external PDF file
Note: This method was superseded byimportPage() in mPDF 8.0.
intImportPage (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 setwithSetSourceFile(). 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. $pageno shouldbe a positive integer value.
Default:1
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
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
Specifies the width in millimetres when importing a ‘cropped’ page into the template.
Default:null uses the full page width from the source file
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 is currently not used.
ImportPage() returns an ID for the template which it has created. This ID can be used at any time to insert the templateinto the document withUseTemplate()orSetPageTemplate()
| Version | Description |
|---|---|
| 2.3 | Function was added. |
Example #1 - Using a full page
<?php// Require composer autoloadrequire_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();| Version | Description |
|---|---|
| 8.0 | Function was replaced byimportPage(). |
Example #2 - Using a ‘cropped’ page
<?php// Require composer autoloadrequire_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();