You are reading the documentation of the legacy and unsupported version 1 of FPDI.
For version 2 please refer to this documentation.

The FPDI Class Initiate and use the FPDI class


The FPDI class is an extension for FPDF allowing you to import existing PDF pages into FPDF. It extends FPDF_TPL which adds a kind of template feature to FPDF.

FPDI transforms a PDF page into the same structure that is used by FPDF_TPL. The class offers all available methods as you already know from FPDF and extends it with some more methods. 


The usage of FPDI follows a simply logic:

  1. Define the document to take pages from.
  2. Import an existing page of the document
  3. Use the imported page on a page created with FPDF

By this you will notice that you will not edit the original document but you will create a completely new document by import another one page by page.


Beside the methods of FPDF and FPDF_TPL the class offers or overwrites following methods (ordered by its usage priority): 


public FPDI::setSourceFile (
string $filename
): int

Set a source-file.

Depending on the PDF version of the used document the PDF version of the resulting document will be adjusted to the higher version.

$filename : string

A valid path to the PDF document from which pages should be imported from

Return Values

The number of pages in the document


Throws Exception


public FPDI::importPage (
int $pageNo [, string $boxName = 'CropBox' [, boolean $groupXObject = true ]]
): int

Import a page.

The second parameter defines the bounding box that should be used to transform the page into a form XObject.

Following values are available: MediaBox, CropBox, BleedBox, TrimBox, ArtBox. If a box is not especially defined its default box will be used:

  • CropBox: Default -> MediaBox
  • BleedBox: Default -> CropBox
  • TrimBox: Default -> CropBox
  • ArtBox: Default -> CropBox

It is possible to get the used page box by the getLastUsedPageBox() method.

$pageNo : int

The page number

$boxName : string

The boundary box to use when transforming the page into a form XObject

$groupXObject : boolean

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

Return Values

An id of the imported page/template to use with e.g. fpdf_tpl::useTemplate()


Throws LogicException,InvalidArgumentException



public FPDI::useTemplate (
int $tplIdx [, int $x = null [, int $y = null [, int $w = 0 [, int $h = 0 [, boolean $adjustPageSize = false ]]]]]
): array

Use a template or imported page in current page or other template.

You can use a template in a page or in another template. You can give the used template a new size. All parameters are optional. The width or height is calculated automatically if one is given. If no parameter is given the origin size as defined in beginTemplate() or of the imported page is used.

The calculated or used width and height are returned as an array.

$tplIdx : int

A valid template-id

$x : int

The x-position

$y : int

The y-position

$w : int

The new width of the template

$h : int

The new height of the template

$adjustPageSize : boolean

If set to true the current page will be resized to fit the dimensions of the template

Return Values

The height and width of the template (array('w' => ..., 'h' => ...))


Throws LogicException,InvalidArgumentException


public FPDI::getLastUsedPageBox (
): string

Returns the last used page boundary box.

Return Values

The used boundary box: MediaBox, CropBox, BleedBox, TrimBox or ArtBox


public FPDI::cleanUp (
): void

Removes cycled references and closes the file handles of the parser objects.