setasign\Fpdi

Fpdi Class Fpdi

File: /FPDI v2/Fpdi.php

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

Class hierarchy

Uses

Summary

Constants

VERSION

const setasign\Fpdi\Fpdi::VERSION = '2.0.0'

FPDI version


Properties

$currentReaderId

protected string setasign\Fpdi\Fpdi::$currentReaderId

The current reader id.

$currentTemplateId

protected null|int setasign\Fpdi\Fpdi::$currentTemplateId

The template id for the currently created template.

$importedPages

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

Data of all imported pages.

$objectMap

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

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

$objectsToCopy

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

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

$readers

protected PdfReader\PdfReader[] setasign\Fpdi\Fpdi::$readers = array()

The pdf reader instances.

$templateId

protected int setasign\Fpdi\Fpdi::$templateId = 0

A counter for template ids.

$templates

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

Data of all created templates.


Methods

Link()

public FpdfTpl::Link (
$x, $y, $w, $h, $link
): void

Parameters
$x
 
$y
 
$w
 
$h
 
$link
 

SetDrawColor()

public FpdfTpl::SetDrawColor (
$r [, $g = null [, $b = null ]]
): void

Parameters
$r
 
$g
 
$b
 

SetFillColor()

public FpdfTpl::SetFillColor (
$r [, $g = null [, $b = null ]]
): void

Parameters
$r
 
$g
 
$b
 

SetFont()

public FpdfTpl::SetFont (
$family [, $style = '' [, $size = 0 ]]
): void

Parameters
$family
 
$style
 
$size
 

SetFontSize()

public FpdfTpl::SetFontSize (
$size
): void

Parameters
$size
 

SetLineWidth()

public FpdfTpl::SetLineWidth (
$width
): void

Parameters
$width
 

SetLink()

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

Parameters
$link
 
$y
 
$page
 

_out()

public FpdfTpl::_out (
$s
): void

Parameters
$s
 

_put()

protected Fpdi::_put (
$s [, $newLine = true ]
): void

Parameters
$s
 
$newLine
 

_putimages()

protected Fpdi::_putimages (
void
): void

_putxobjectdict()

protected Fpdi::_putxobjectdict (
void
): void

beginTemplate()

public FpdfTpl::beginTemplate (
[ float|int|null $width = null [, float|int|null $height = null ]]
): 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.

Return Values

A template identifier.

endTemplate()

public FpdfTpl::endTemplate (
void
): bool|int|null

Ends a template.

Return Values

A template identifier.

getImportedPageSize()

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

Get the size of an imported page.

Omit 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()

protected FpdfTpl::getNextTemplateId (
void
): int

Get the next template id.

getPdfParserInstance()

protected FpdiTrait::getPdfParserInstance (
PdfParser\StreamReader $streamReader
): PdfParser\PdfParser|\setasign\FpdiPdfParser\PdfParser\PdfParser

Get a new pdf parser instance.

Parameters
$streamReader : PdfParser\StreamReader
 

getPdfReader()

protected FpdiTrait::getPdfReader (
string $id
): PdfReader\PdfReader

Get a pdf reader instance by its id.

Parameters
$id : string
 

getPdfReaderId()

protected FpdiTrait::getPdfReaderId (): string

Get an unique reader id by the $file parameter.

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

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

getTemplateSize()

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

Get the size of an imported page or template.

Omit 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 FpdiTrait::importPage (
int $pageNumber [, string $box = setasign\Fpdi\PdfReader\PageBoundaries::CROP_BOX [, bool $groupXObject = true ]]
): 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).

Return Values

A unique string identifying the imported page.

Exceptions

Throws PdfReader\PdfReaderException

See
  • PageBoundaries

setMinPdfVersion()

protected FpdiTrait::setMinPdfVersion (
string $pdfVersion
): void

Set the minimal PDF version.

Parameters
$pdfVersion : string
 

setPageFormat()

public FpdfTpl::setPageFormat (
string $size, array $orientation
): void

Set the page format of the current page.

Parameters
$size : string

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

$orientation : array

An array with two values defining the size.

setSourceFile()

public FpdiTrait::setSourceFile (
string|resource|PdfParser\StreamReader $file
): int

Set the source PDF file.

Parameters
$file : string|resource|PdfParser\StreamReader

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

Return Values

The page count of the PDF document.

useImportedPage()

public 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.

Omit 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 Fpdi::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.

Omit 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()

protected FpdiTrait::writePdfType (): void

Writes a PdfType object to the resulting buffer.

Parameters
$value : PdfParser\Type\PdfType