FPDI Class FPDI

File: /FPDI v1/fpdi.php

Class hierarchy

Summary

Constants

VERSION

const FPDI::VERSION = '1.6.2'

FPDI version


Properties

$_currentObjId

protected integer FPDI::$_currentObjId

Current Object Id.

$_doneObjStack

protected array FPDI::$_doneObjStack

Done object stack

$_importedPages

protected array FPDI::$_importedPages = array()

Cache for imported pages/template ids

$_inTpl

protected boolean FPDF_TPL::$_inTpl = false

"In Template"-Flag

$_objStack

protected array FPDI::$_objStack

Object stack

$_res

protected array FPDF_TPL::$_res = array()

Resources used by templates and pages

$_tpls

protected array FPDF_TPL::$_tpls = array()

Array of template data

$currentFilename

public string FPDI::$currentFilename

Actual filename

$currentParser

Current parser

$lastUsedPageBox

public string FPDI::$lastUsedPageBox

The name of the last imported page box

$lastUsedTemplateData

public array FPDF_TPL::$lastUsedTemplateData = array()

Last used template data

$parsers

public fpdi_pdf_parser[] FPDI::$parsers = array()

Parser-Objects

$tpl

public int FPDF_TPL::$tpl = 0

Current Template-Id

$tplPrefix

public string FPDF_TPL::$tplPrefix = '/TPL'

A String defining the Prefix used as Template-Object-Names. Have to begin with an /

Name prefix of templates used in Resources dictionary


Methods

AddLink()

public FPDF_TPL::AddLink (
void
): void

Creates a new internal link and returns its identifier.

Overwritten because adding links in a template will not work.

See

AddPage()

public FPDF_TPL::AddPage (
[ $orientation = '' [, $format = '' [, $rotationOrKeepmargins = false [, $tocpage = false ]]]]
): void

Adds a new page to the document.

See FPDF/TCPDF documentation.

This method cannot be used if you'd started a template.

Parameters
$orientation
 
$format
 
$rotationOrKeepmargins
 
$tocpage
 
See

Image()

public FPDF_TPL::Image (
$file [, $x = '' [, $y = '' [, $w = 0 [, $h = 0 [, $type = '' [, $link = '' [, $align = '' [, $resize = false [, $dpi = 300 [, $palign = '' [, $ismask = false [, $imgmask = false [, $border = 0 [, $fitbox = false [, $hidden = false [, $fitonpage = false [, $alt = false [, $altimgs = array ( ) ]]]]]]]]]]]]]]]]]]
): void

Puts an image.

See FPDF/TCPDF documentation.

Parameters
$file
 
$x
 
$y
 
$w
 
$h
 
$type
 
$link
 
$align
 
$resize
 
$dpi
 
$palign
 
$ismask
 
$imgmask
 
$border
 
$fitbox
 
$hidden
 
$fitonpage
 
$alt
 
$altimgs
 
See

Link()

public FPDF_TPL::Link (
$x, $y, $w, $h, $link [, $spaces = 0 ]
): void

Puts a link on a rectangular area of the page.

Overwritten because adding links in a template will not work.

Parameters
$x
 
$y
 
$w
 
$h
 
$link
 
$spaces
 
See

SetFont()

public FPDF_TPL::SetFont (
$family [, $style = '' [, $size = null [, $fontfile = '' [, $subset = 'default' [, $out = true ]]]]]
): void

Sets the font used to print character strings.

See FPDF/TCPDF documentation.

Parameters
$family
 
$style
 
$size
 
$fontfile
 
$subset
 
$out
 
See

SetLink()

public FPDF_TPL::SetLink (
$link [, $y = 0 [, $page = null ]]
): void

Defines the page and position a link points to.

Overwritten because adding links in a template will not work.

Parameters
$link
 
$y
 
$page
 
See

_closeParsers()

protected FPDI::_closeParsers (
void
): boolean

Close all files opened by parsers.

_enddoc()

public FPDI::_enddoc (
void
): void

Ends the document

Overwritten to close opened parsers

_getPdfParser()

protected FPDI::_getPdfParser (
string $filename
): fpdi_pdf_parser

Returns a PDF parser object

Parameters
$filename : string
 

_newobj()

public FPDI::_newobj (
[ bool $objId = false [, bool $onlyNewObj = false ]]
): bool|int

Creates and optionally write the object definition to the document.

Rewritten to handle existing own defined objects

Parameters
$objId : bool
 
$onlyNewObj : bool
 

_out()

public FPDF_TPL::_out (
string $s
): void

Writes bytes to the resulting document.

Overwritten to delegate the data to the template buffer.

Parameters
$s : string
 

_putformxobjects()

protected FPDI::_putformxobjects (
void
): void

Writes the form XObjects to the PDF document.

_putimages()

public FPDF_TPL::_putimages (
void
): void

Output images.

Overwritten to add _putformxobjects() after _putimages().

_putimportedobjects()

protected FPDI::_putimportedobjects (
void
): void

Copy all imported objects to the resulting document.

_putxobjectdict()

public FPDF_TPL::_putxobjectdict (
void
): void

Writes the references of XObject resources to the document.

Overwritten to add the the templates to the XObject resource dictionary.

_straightOut()

protected FPDI::_straightOut (
$s
): void

Modified _out() method so not each call will add a newline to the output.

Parameters
$s
 

_writeValue()

protected FPDI::_writeValue (
mixed &$value
): void

Writes a PDF value to the resulting document.

Needed to rebuild the source document

Parameters
$value : mixed

A PDF-Value. Structure of values see cases in this method

beginTemplate()

public FPDF_TPL::beginTemplate (
[ int $x = null [, int $y = null [, int $w = null [, int $h = null ]]]]
): int

Start a template.

This method starts a template. You can give own coordinates to build an own sized template. Pay attention, that the margins are adapted to the new template size. If you want to write outside the template, for example to build a clipped template, you have to set the margins and "cursor"-position manual after beginTemplate()-call.

If no parameter is given, the template uses the current page-size. The method returns an id of the current template. This id is used later for using this template. Warning: A created template is saved in the resulting PDF at all events. Also if you don't use it after creation!

Parameters
$x : int

The x-coordinate given in user-unit

$y : int

The y-coordinate given in user-unit

$w : int

The width given in user-unit

$h : int

The height given in user-unit

Return Values

The id of new created template

Exceptions

Throws LogicException

cleanUp()

public FPDI::cleanUp (
void
): void

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

endTemplate()

public FPDF_TPL::endTemplate (
void
): int|boolean

End template.

This method ends a template and reset initiated variables collected in beginTemplate().

Return Values

If a template is opened, the id is returned. If not a false is returned.

getLastUsedPageBox()

public FPDI::getLastUsedPageBox (
void
): string

Returns the last used page boundary box.

Return Values

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

getPdfVersion()

public FPDI::getPdfVersion (
void
): string

Get the current PDF version.

getTemplateSize()

public FPDF_TPL::getTemplateSize (
int $tplIdx [, int $w = 0 [, int $h = 0 ]]
): array

Get the calculated size of a template.

If one size is given, this method calculates the other one.

Parameters
$tplIdx : int

A valid template-id

$w : int

The width of the template

$h : int

The height of the template

Return Values

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

importPage()

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.

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

Exceptions

Throws LogicException,InvalidArgumentException

See

setPdfVersion()

public FPDI::setPdfVersion (
[ string $version = '1.3' ]
): void

Set the PDF version.

Parameters
$version : string
 

setSourceFile()

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.

Parameters
$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

Exceptions

Throws Exception

useTemplate()

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.

Parameters
$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' => ...))

Exceptions

Throws LogicException,InvalidArgumentException