Documentation

Fpdi extends TCPDF
in package
uses FpdiTrait

Class Fpdi

This class let you import pages of existing PDF documents into a reusable structure for TCPDF.

Table of Contents

Constants

VERSION  = '2.6.6'
FPDI version

Properties

$createdReaders  : array<string|int, mixed>
Instances created internally.
$currentObjectNumber  : int|null
The currently used object number.
$currentReaderId  : string|null
The current reader id.
$importedPages  : array<string|int, mixed>
Data of all imported pages.
$objectMap  : array<string|int, mixed>
A map from object numbers of imported objects to new assigned object numbers by FPDF.
$objectsToCopy  : array<string|int, mixed>
An array with information about objects, which needs to be copied to the resulting document.
$readers  : array<string|int, PdfReader>
The pdf reader instances.
$templateId  : int
A counter for template ids.

Methods

_encrypt_data()  : void
cleanUp()  : mixed
Release resources and file handles.
getImportedPageSize()  : array<string|int, mixed>|bool
Get the size of an imported page.
getTemplateSize()  : array<string|int, mixed>|bool
Get the size of an imported page.
importPage()  : string
Imports a page.
setSourceFile()  : int
Set the source PDF file.
setSourceFileWithParserParams()  : int
Set the source PDF file with parameters which are passed to the parser instance.
useImportedPage()  : array<string|int, mixed>
Draws an imported page onto the page.
useTemplate()  : array<string|int, mixed>
Draws an imported page onto the page or another template.
_enddoc()  : mixed
_getxobjectdict()  : string
_newobj()  : int
Begin a new object and return the object number.
_put()  : mixed
Append content to the buffer of TCPDF.
_putxobjects()  : mixed
adjustLastLink()  : void
This method will add additional data to the last created link/annotation.
getNextTemplateId()  : int
Get the next template id.
getPdfParserInstance()  : PdfParser|PdfParser
Get a new pdf parser instance.
getPdfReader()  : PdfReader
Get a pdf reader instance by its id.
getPdfReaderId()  : string
Get an unique reader id by the $file parameter.
setMinPdfVersion()  : mixed
Set the minimal PDF version.
writePdfType()  : mixed
Writes a PdfType object to the resulting buffer.

Constants

VERSION

FPDI version

public mixed VERSION = '2.6.6'
Tags
string

Properties

$createdReaders

Instances created internally.

protected array<string|int, mixed> $createdReaders = []

$currentObjectNumber

The currently used object number.

protected int|null $currentObjectNumber

$currentReaderId

The current reader id.

protected string|null $currentReaderId

$importedPages

Data of all imported pages.

protected array<string|int, mixed> $importedPages = []

$objectMap

A map from object numbers of imported objects to new assigned object numbers by FPDF.

protected array<string|int, mixed> $objectMap = []

$objectsToCopy

An array with information about objects, which needs to be copied to the resulting document.

protected array<string|int, mixed> $objectsToCopy = []

$templateId

A counter for template ids.

protected int $templateId = 0

Methods

_encrypt_data()

public _encrypt_data(int $n, string $s) : void

string

Parameters
$n : int
$s : string

cleanUp()

Release resources and file handles.

public cleanUp([bool $allReaders = false ]) : mixed

This method is called internally when the document is created successfully. By default it only cleans up stream reader instances which were created internally.

Parameters
$allReaders : bool = false

getImportedPageSize()

Get the size of an imported page.

public getImportedPageSize(mixed $tpl[, float|int|null $width = null ][, float|int|null $height = null ]) : array<string|int, mixed>|bool

Give only one of the size parameters (width, height) to calculate the other one automatically in view to the aspect ratio.

Parameters
$tpl : mixed

The template id

$width : float|int|null = null

The width.

$height : float|int|null = null

The height.

Return values
array<string|int, mixed>|bool

An array with following keys: width, height, 0 (=width), 1 (=height), orientation (L or P)

getTemplateSize()

Get the size of an imported page.

public getTemplateSize(mixed $tpl[, float|int|null $width = null ][, float|int|null $height = null ]) : array<string|int, mixed>|bool

Give only one of the size parameters (width, height) to calculate the other one automatically in view to the aspect ratio.

Parameters
$tpl : mixed

The template id

$width : float|int|null = null

The width.

$height : float|int|null = null

The height.

Return values
array<string|int, mixed>|bool

An array with following keys: width, height, 0 (=width), 1 (=height), orientation (L or P)

importPage()

Imports a page.

public importPage(int $pageNumber[, string $box = PageBoundaries::CROP_BOX ][, bool $groupXObject = true ][, bool $importExternalLinks = false ]) : string
Parameters
$pageNumber : int

The page number.

$box : string = PageBoundaries::CROP_BOX

The page boundary to import. Default set to PageBoundaries::CROP_BOX.

$groupXObject : bool = true

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

$importExternalLinks : bool = false

Define whether external links are imported or not.

Tags
throws
CrossReferenceException
throws
FilterException
throws
PdfParserException
throws
PdfTypeException
throws
PdfReaderException
see
PageBoundaries
Return values
string

A unique string identifying the imported page.

setSourceFile()

Set the source PDF file.

public setSourceFile(string|resource|StreamReader $file) : int
Parameters
$file : string|resource|StreamReader

Path to the file or a stream resource or a StreamReader instance.

Tags
throws
PdfParserException
Return values
int

The page count of the PDF document.

setSourceFileWithParserParams()

Set the source PDF file with parameters which are passed to the parser instance.

public setSourceFileWithParserParams(string|resource|StreamReader $file[, array<string|int, mixed> $parserParams = [] ]) : int

This method allows us to pass e.g. authentication information to the parser instance.

Parameters
$file : string|resource|StreamReader

Path to the file or a stream resource or a StreamReader instance.

$parserParams : array<string|int, mixed> = []

Individual parameters passed to the parser instance.

Tags
throws
CrossReferenceException
throws
PdfParserException
throws
PdfTypeException
Return values
int

The page count of the PDF document.

useImportedPage()

Draws an imported page onto the page.

public useImportedPage(mixed $pageId[, float|int|array<string|int, mixed> $x = 0 ][, float|int $y = 0 ][, float|int|null $width = null ][, float|int|null $height = null ][, bool $adjustPageSize = false ]) : array<string|int, mixed>

Give only one of the size parameters (width, height) to calculate the other one automatically in view to the aspect ratio.

Parameters
$pageId : mixed

The page id

$x : float|int|array<string|int, mixed> = 0

The abscissa of upper-left corner. Alternatively you could use an assoc array with the keys "x", "y", "width", "height", "adjustPageSize".

$y : float|int = 0

The ordinate of upper-left corner.

$width : float|int|null = null

The width.

$height : float|int|null = null

The height.

$adjustPageSize : bool = false
Tags
see
Fpdi::getTemplateSize()
Return values
array<string|int, mixed>

The size.

useTemplate()

Draws an imported page onto the page or another template.

public useTemplate(mixed $tpl[, float|int|array<string|int, mixed> $x = 0 ][, float|int $y = 0 ][, float|int|null $width = null ][, float|int|null $height = null ][, bool $adjustPageSize = false ]) : array<string|int, mixed>

Give only one of the size parameters (width, height) to calculate the other one automatically in view to the aspect ratio.

Parameters
$tpl : mixed

The template id

$x : float|int|array<string|int, mixed> = 0

The abscissa of upper-left corner. Alternatively you could use an assoc array with the keys "x", "y", "width", "height", "adjustPageSize".

$y : float|int = 0

The ordinate of upper-left corner.

$width : float|int|null = null

The width.

$height : float|int|null = null

The height.

$adjustPageSize : bool = false
Tags
see
FpdiTrait::getTemplateSize()
Return values
array<string|int, mixed>

The size

_enddoc()

protected _enddoc() : mixed

_getxobjectdict()

protected _getxobjectdict() : string
Tags
inheritdoc
Return values
string

_newobj()

Begin a new object and return the object number.

protected _newobj([int|string $objid = '' ]) : int
Parameters
$objid : int|string = ''

Object ID (leave empty to get a new ID).

Return values
int

object number

_put()

Append content to the buffer of TCPDF.

protected _put(string $s[, bool $newLine = true ]) : mixed
Parameters
$s : string
$newLine : bool = true

This method will add additional data to the last created link/annotation.

protected adjustLastLink(array<string|int, mixed> $externalLink, float|int $xPt, float|int $scaleX, float|int $yPt, float|int $newHeightPt, float|int $scaleY, array<string|int, mixed> $importedPage) : void

It will copy styling properties (supported by TCPDF) of the imported link.

Parameters
$externalLink : array<string|int, mixed>
$xPt : float|int
$scaleX : float|int
$yPt : float|int
$newHeightPt : float|int
$scaleY : float|int
$importedPage : array<string|int, mixed>

getNextTemplateId()

Get the next template id.

protected getNextTemplateId() : int
Return values
int

getPdfParserInstance()

Get a new pdf parser instance.

protected getPdfParserInstance(StreamReader $streamReader[, array<string|int, mixed> $parserParams = [] ]) : PdfParser|PdfParser
Parameters
$streamReader : StreamReader
$parserParams : array<string|int, mixed> = []

Individual parameters passed to the parser instance.

Return values
PdfParser|PdfParser

getPdfReader()

Get a pdf reader instance by its id.

protected getPdfReader(string $id) : PdfReader
Parameters
$id : string
Return values
PdfReader

getPdfReaderId()

Get an unique reader id by the $file parameter.

protected getPdfReaderId(string|resource|PdfReader|StreamReader $file[, array<string|int, mixed> $parserParams = [] ]) : string
Parameters
$file : string|resource|PdfReader|StreamReader

An open file descriptor, a path to a file, a PdfReader instance or a StreamReader instance.

$parserParams : array<string|int, mixed> = []

Individual parameters passed to the parser instance.

Return values
string

setMinPdfVersion()

Set the minimal PDF version.

protected setMinPdfVersion(string $pdfVersion) : mixed
Parameters
$pdfVersion : string

        
On this page

Search results