setasign\Fpdi\Tfpdf

Fpdi Class Fpdi

File: /FPDI v2/Tfpdf/Fpdi.php

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

Class hierarchy

Uses

Summary

Constants

VERSION

public const Fpdi::VERSION = '2.6.0'

FPDI version


Properties

$createdReaders

protected array \setasign\Fpdi\FpdiTrait::$createdReaders = array()

Instances created internally.

$currentReaderId

The current reader id.

$currentTemplateId

The template id for the currently created template.

$importedPages

protected array \setasign\Fpdi\FpdiTrait::$importedPages = array()

Data of all imported pages.

$objectMap

protected array \setasign\Fpdi\FpdiTrait::$objectMap = array()

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

$objectsToCopy

protected array \setasign\Fpdi\FpdiTrait::$objectsToCopy = array()

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

$readers

The pdf reader instances.

$templateId

A counter for template ids.

$templates

protected array \setasign\Fpdi\FpdfTplTrait::$templates = array()

Data of all created templates.


Methods

AddPage()

public \setasign\Fpdi\FpdfTplTrait::AddPage (
[ $orientation = '' [, $size = '' [, $rotation = 0 ]]]
): void
Parameters
$orientation
 
$size
 
$rotation
 

Link()

public \setasign\Fpdi\FpdfTplTrait::Link (
$x, $y, $w, $h, $link
): void
Parameters
$x
 
$y
 
$w
 
$h
 
$link
 

SetDrawColor()

public \setasign\Fpdi\FpdfTplTrait::SetDrawColor (
$r [, $g = null [, $b = null ]]
): void
Parameters
$r
 
$g
 
$b
 

SetFillColor()

public \setasign\Fpdi\FpdfTplTrait::SetFillColor (
$r [, $g = null [, $b = null ]]
): void
Parameters
$r
 
$g
 
$b
 

SetFont()

public \setasign\Fpdi\FpdfTplTrait::SetFont (
$family [, $style = '' [, $size = 0 ]]
): void
Parameters
$family
 
$style
 
$size
 

SetFontSize()

Parameters
$size
 

SetLineWidth()

public \setasign\Fpdi\FpdfTplTrait::SetLineWidth (
$width
): void
Parameters
$width
 

SetLink()

public \setasign\Fpdi\FpdfTplTrait::SetLink (
$link [, $y = 0 [, $page = -1 ]]
): void
Parameters
$link
 
$y
 
$page
 

_enddoc()

protected \setasign\Fpdi\FpdfTrait::_enddoc (
void
): void

_out()

public \setasign\Fpdi\FpdfTplTrait::_out (
$s
): void
Parameters
$s
 

_put()

protected \setasign\Fpdi\FpdfTrait::_put (
$s [, $newLine = true ]
): void
Parameters
$s
 
$newLine
 

_putlinks()

protected \setasign\Fpdi\FpdfTrait::_putlinks (
int $n
): void
Parameters
$n : int
 
Exceptions

Throws \setasign\Fpdi\PdfParser\Type\PdfTypeException

_putxobjectdict()

protected \setasign\Fpdi\FpdfTrait::_putxobjectdict (
void
): void

adjustLastLink()

protected \setasign\Fpdi\FpdiTrait::adjustLastLink (
array $externalLink, float|int $xPt, float|int $scaleX, float|int $yPt, float|int $newHeightPt, float|int $scaleY, array $importedPage
): void

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

It is separated because TCPDF uses its own logic to handle link annotations. This method is overwritten in the TCPDF implementation.

Parameters
$externalLink : array
 
$xPt : float|int
 
$scaleX : float|int
 
$yPt : float|int
 
$newHeightPt : float|int
 
$scaleY : float|int
 
$importedPage : array
 

beginTemplate()

public \setasign\Fpdi\FpdfTplTrait::beginTemplate (
[ float|int|null $width = null [, float|int|null $height = null [, bool $groupXObject = false ]]]
): int

Begins a new template.

Parameters
$width : float|int|null

The width of the template. If null, the current page width is used.

$height : float|int|null

The height of the template. If null, the current page height is used.

$groupXObject : bool

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

Return Values

A template identifier.

cleanUp()

public \setasign\Fpdi\FpdiTrait::cleanUp (
[ bool $allReaders = false ]
): void

Release resources and file handles.

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
 

endTemplate()

public \setasign\Fpdi\FpdfTplTrait::endTemplate (
void
): bool|int|null

Ends a template.

Return Values

A template identifier.

getImportedPageSize()

public \setasign\Fpdi\FpdiTrait::getImportedPageSize (
mixed $tpl [, float|int|null $width = null [, float|int|null $height = null ]]
): array|bool

Get the size of an imported page.

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

The width.

$height : float|int|null

The height.

Return Values

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

getNextTemplateId()

Get the next template id.

getPdfParserInstance()

protected \setasign\Fpdi\FpdiTrait::getPdfParserInstance (
\setasign\Fpdi\PdfParser\StreamReader $streamReader [, array $parserParams = array ( ) ]
): \setasign\Fpdi\PdfParser\PdfParser|\setasign\FpdiPdfParser\PdfParser\PdfParser

Get a new pdf parser instance.

Parameters
$streamReader : \setasign\Fpdi\PdfParser\StreamReader
 
$parserParams : array

Individual parameters passed to the parser instance.

getPdfReader()

Get a pdf reader instance by its id.

Parameters
$id : string
 

getPdfReaderId()

protected \setasign\Fpdi\FpdiTrait::getPdfReaderId (
string|resource|\setasign\Fpdi\PdfReader\PdfReader|\setasign\Fpdi\PdfParser\StreamReader $file [, array $parserParams = array ( ) ]
): string

Get an unique reader id by the $file parameter.

Parameters
$file : string|resource|\setasign\Fpdi\PdfReader\PdfReader|\setasign\Fpdi\PdfParser\StreamReader

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

$parserParams : array

Individual parameters passed to the parser instance.

getTemplateSize()

public \setasign\Fpdi\FpdfTrait::getTemplateSize (
mixed $tpl [, float|int|null $width = null [, float|int|null $height = null ]]
): array|bool

Get the size of an imported page or template.

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

The width.

$height : float|int|null

The height.

Return Values

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

importPage()

public \setasign\Fpdi\FpdiTrait::importPage (
int $pageNumber [, string $box = \setasign\Fpdi\PdfReader\PageBoundaries::CROP_BOX [, bool $groupXObject = true [, bool $importExternalLinks = false ]]]
): string

Imports a page.

Parameters
$pageNumber : int

The page number.

$box : string

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

$groupXObject : bool

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

$importExternalLinks : bool

Define whether external links are imported or not.

Return Values

A unique string identifying the imported page.

Exceptions

Throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException

Throws \setasign\Fpdi\PdfParser\Filter\FilterException

Throws \setasign\Fpdi\PdfParser\PdfParserException

Throws \setasign\Fpdi\PdfParser\Type\PdfTypeException

Throws \setasign\Fpdi\PdfReader\PdfReaderException

See
  • PageBoundaries

setMinPdfVersion()

protected \setasign\Fpdi\FpdiTrait::setMinPdfVersion (
string $pdfVersion
): void

Set the minimal PDF version.

Parameters
$pdfVersion : string
 

setPageFormat()

public \setasign\Fpdi\FpdfTplTrait::setPageFormat (
array $size, string $orientation
): void

Set the page format of the current page.

Parameters
$size : array

An array with two values defining the size.

$orientation : string

"L" for landscape, "P" for portrait.

Exceptions

Throws \BadMethodCallException

setSourceFile()

Set the source PDF file.

Parameters
$file : string|resource|\setasign\Fpdi\PdfParser\StreamReader

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

Return Values

The page count of the PDF document.

Exceptions

Throws \setasign\Fpdi\PdfParser\PdfParserException

setSourceFileWithParserParams()

public \setasign\Fpdi\FpdiTrait::setSourceFileWithParserParams (
string|resource|\setasign\Fpdi\PdfParser\StreamReader $file [, array $parserParams = array ( ) ]
): int

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

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

Parameters
$file : string|resource|\setasign\Fpdi\PdfParser\StreamReader

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

$parserParams : array

Individual parameters passed to the parser instance.

Return Values

The page count of the PDF document.

Exceptions

Throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException

Throws \setasign\Fpdi\PdfParser\PdfParserException

Throws \setasign\Fpdi\PdfParser\Type\PdfTypeException

useImportedPage()

public \setasign\Fpdi\FpdiTrait::useImportedPage (
mixed $pageId [, float|int|array $x = 0 [, float|int $y = 0 [, float|int|null $width = null [, float|int|null $height = null [, bool $adjustPageSize = false ]]]]]
): array

Draws an imported page onto the page.

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

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

$y : float|int

The ordinate of upper-left corner.

$width : float|int|null

The width.

$height : float|int|null

The height.

$adjustPageSize : bool
 
Return Values

The size.

See

useTemplate()

public \setasign\Fpdi\FpdfTrait::useTemplate (
mixed $tpl [, float|int|array $x = 0 [, float|int $y = 0 [, float|int|null $width = null [, float|int|null $height = null [, bool $adjustPageSize = false ]]]]]
): array

Draws an imported page or a template onto the page or another template.

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

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

$y : float|int

The ordinate of upper-left corner.

$width : float|int|null

The width.

$height : float|int|null

The height.

$adjustPageSize : bool
 
Return Values

The size

See

writePdfType()

Writes a PdfType object to the resulting buffer.

Parameters
$value : \setasign\Fpdi\PdfParser\Type\PdfType
 
Exceptions

Throws \setasign\Fpdi\PdfParser\Type\PdfTypeException