Fpdi
extends FpdfTpl
in package
uses
FpdiTrait, FpdfTrait
Class Fpdi
This class let you import pages of existing PDF documents into a reusable structure for tFPDF.
Table of Contents
Constants
- VERSION = '2.6.6'
- FPDI version
Properties
- $createdReaders : array<string|int, mixed>
- Instances created internally.
- $currentReaderId : string|null
- The current reader id.
- $currentTemplateId : null|int
- The template id for the currently created template.
- $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.
- $templates : array<string|int, mixed>
- Data of all created templates.
Methods
- _out() : mixed
- AddPage() : mixed
- beginTemplate() : int
- Begins a new template.
- cleanUp() : mixed
- Release resources and file handles.
- endTemplate() : bool|int|null
- Ends a template.
- 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 or template.
- importPage() : string
- Imports a page.
- Link() : mixed
- SetDrawColor() : mixed
- SetFillColor() : mixed
- SetFont() : mixed
- SetFontSize() : mixed
- SetLineWidth() : mixed
- SetLink() : mixed
- setPageFormat() : mixed
- Set the page format of the current 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 or a template onto the page or another template.
- _enddoc() : mixed
- _put() : mixed
- _putimages() : mixed
- _putlinks() : void
- _putxobjectdict() : 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
Properties
$createdReaders
Instances created internally.
protected
array<string|int, mixed>
$createdReaders
= []
$currentReaderId
The current reader id.
protected
string|null
$currentReaderId
$currentTemplateId
The template id for the currently created template.
protected
null|int
$currentTemplateId
$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
= []
$readers
The pdf reader instances.
protected
array<string|int, PdfReader>
$readers
= []
$templateId
A counter for template ids.
protected
int
$templateId
= 0
$templates
Data of all created templates.
protected
array<string|int, mixed>
$templates
= []
Methods
_out()
public
_out(mixed $s) : mixed
Parameters
- $s : mixed
Tags
AddPage()
public
AddPage([mixed $orientation = '' ][, mixed $size = '' ][, mixed $rotation = 0 ]) : mixed
Parameters
- $orientation : mixed = ''
- $size : mixed = ''
- $rotation : mixed = 0
Tags
beginTemplate()
Begins a new template.
public
beginTemplate([float|int|null $width = null ][, float|int|null $height = null ][, bool $groupXObject = false ]) : int
Parameters
- $width : float|int|null = null
-
The width of the template. If null, the current page width is used.
- $height : float|int|null = null
-
The height of the template. If null, the current page height is used.
- $groupXObject : bool = false
-
Define the form XObject as a group XObject to support transparency (if used).
Return values
int —A template identifier.
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
endTemplate()
Ends a template.
public
endTemplate() : bool|int|null
Return values
bool|int|null —A template identifier.
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 or template.
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
Return values
string —A unique string identifying the imported page.
Link()
public
Link(mixed $x, mixed $y, mixed $w, mixed $h, mixed $link) : mixed
Parameters
- $x : mixed
- $y : mixed
- $w : mixed
- $h : mixed
- $link : mixed
Tags
SetDrawColor()
public
SetDrawColor(mixed $r[, mixed $g = null ][, mixed $b = null ]) : mixed
Parameters
- $r : mixed
- $g : mixed = null
- $b : mixed = null
Tags
SetFillColor()
public
SetFillColor(mixed $r[, mixed $g = null ][, mixed $b = null ]) : mixed
Parameters
- $r : mixed
- $g : mixed = null
- $b : mixed = null
Tags
SetFont()
public
SetFont(mixed $family[, mixed $style = '' ][, mixed $size = 0 ]) : mixed
Parameters
- $family : mixed
- $style : mixed = ''
- $size : mixed = 0
Tags
SetFontSize()
public
SetFontSize(mixed $size) : mixed
Parameters
- $size : mixed
Tags
SetLineWidth()
public
SetLineWidth(mixed $width) : mixed
Parameters
- $width : mixed
Tags
SetLink()
public
SetLink(mixed $link[, mixed $y = 0 ][, mixed $page = -1 ]) : mixed
Parameters
- $link : mixed
- $y : mixed = 0
- $page : mixed = -1
Tags
setPageFormat()
Set the page format of the current page.
public
setPageFormat(array<string|int, mixed> $size, string $orientation) : mixed
Parameters
- $size : array<string|int, mixed>
-
An array with two values defining the size.
- $orientation : string
-
"L" for landscape, "P" for portrait.
Tags
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
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
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
Return values
array<string|int, mixed> —The size.
useTemplate()
Draws an imported page or a template 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
Return values
array<string|int, mixed> —The size
_enddoc()
protected
_enddoc() : mixed
_put()
protected
_put(mixed $s[, mixed $newLine = true ]) : mixed
Parameters
- $s : mixed
- $newLine : mixed = true
_putimages()
protected
_putimages() : mixed
Tags
_putlinks()
protected
_putlinks(int $n) : void
Parameters
- $n : int
Tags
_putxobjectdict()
protected
_putxobjectdict() : mixed
Tags
adjustLastLink()
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 is separated because TCPDF uses its own logic to handle link annotations. This method is overwritten in the TCPDF implementation.
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
intgetPdfParserInstance()
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|PdfParsergetPdfReader()
Get a pdf reader instance by its id.
protected
getPdfReader(string $id) : PdfReader
Parameters
- $id : string
Return values
PdfReadergetPdfReaderId()
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
stringsetMinPdfVersion()
Set the minimal PDF version.
protected
setMinPdfVersion(string $pdfVersion) : mixed
Parameters
- $pdfVersion : string
writePdfType()
Writes a PdfType object to the resulting buffer.
protected
writePdfType(PdfType $value) : mixed
Parameters
- $value : PdfType