FpdiTrait
The FpdiTrait
This trait offers the core functionalities of FPDI. By passing them to a trait we can reuse it with e.g. TCPDF in a very easy way.
Table of Contents
Properties
- $createdReaders : array<string|int, mixed>
- Instances created internally.
- $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.
Methods
- cleanUp() : mixed
- Release resources and file handles.
- getImportedPageSize() : 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.
- adjustLastLink() : void
- This method will add additional data to the last created link/annotation.
- 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.
Properties
$createdReaders
Instances created internally.
protected
array<string|int, mixed>
$createdReaders
= []
$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
= []
$readers
The pdf reader instances.
protected
array<string|int, PdfReader>
$readers
= []
Methods
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)
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.
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.
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>
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|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