Tcpdf

Tcpdf PDF class

Table of contents

Namespace: Com\Tecnick\Pdf

Extends: Output

File: Tcpdf.php line 91

Tcpdf PDF class

Tags

  • since: 2002-08-03
  • category: Library
  • author: Nicola Asuni info@tecnick.com
  • copyright: 2002-2026 Nicola Asuni - Tecnick.com LTD
  • license: https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
  • link: https://github.com/tecnickcom/tc-lib-pdf
  • phpstan-import-type: StyleDataOpt from \Com\Tecnick\Pdf\Graph\Base
  • phpstan-import-type: PageData from \Com\Tecnick\Pdf\Page\Box
  • phpstan-import-type: PageInputData from \Com\Tecnick\Pdf\Page\Box
  • phpstan-import-type: TFontMetric from \Com\Tecnick\Pdf\Font\Stack
  • phpstan-import-type: TSignature from \Com\Tecnick\Pdf\Base
  • phpstan-import-type: TSignDocPrepared from \Com\Tecnick\Pdf\Base
  • phpstan-import-type: TSignTimeStamp from \Com\Tecnick\Pdf\Base
  • phpstan-import-type: TUserRights from \Com\Tecnick\Pdf\Base
  • phpstan-import-type: TFileOptions from Base
  • mixin
  • mixin
  • SuppressWarnings: (“PHPMD.DepthOfInheritance”)

Constants

BORDERPOS_DEFAULT

File: Base.php line 1405

public mixed BORDERPOS_DEFAULT = 0.0

BORDERPOS_EXTERNAL

File: Base.php line 1411

public mixed BORDERPOS_EXTERNAL = -0.5

BORDERPOS_INTERNAL

File: Base.php line 1417

public mixed BORDERPOS_INTERNAL = 0.5

ZEROCELL

File: Base.php line 1436

public TCellDef ZEROCELL = ['margin' => self::ZEROCELLBOUND, 'padding' => self::ZEROCELLBOUND, 'borderpos' => self::BORDERPOS_DEFAULT]

ZEROCELLBOUND

File: Base.php line 1424

public TCellBound ZEROCELLBOUND = ['T' => 0.0, 'R' => 0.0, 'B' => 0.0, 'L' => 0.0]

Properties

$author

File: MetaInfo.php line 0

public string $author

$barcode

File: Base.php line 732

public Barcode $barcode

$cache

File: Base.php line 747

public Cache $cache

$color

File: Base.php line 727

public PdfColor $color

$compress

File: Tcpdf.php line 0

public bool $compress

$creator

File: MetaInfo.php line 0

public string $creator

$custom_xmp

File: MetaInfo.php line 0

public array<string, string> $custom_xmp

$defcell

File: Tcpdf.php line 0

public array<string, mixed> $defcell

$defPageContentEnabled

File: Tcpdf.php line 0

public bool $defPageContentEnabled

$display

File: Tcpdf.php line 0

public array{zoom: int|string, layout: string, mode: string} $display

$docmodtime

File: MetaInfo.php line 0

public int $docmodtime

$doctime

File: MetaInfo.php line 0

public int $doctime

$encpdffilename

File: Tcpdf.php line 0

public string $encpdffilename

$encrypt

File: MetaInfo.php line 0

public Encrypt $encrypt

$file

File: Base.php line 737

public File $file

$fileid

File: MetaInfo.php line 0

public string $fileid

$font

File: Base.php line 773

public Stack $font

$graph

File: Base.php line 768

public Draw $graph

$hybriddoc

File: MetaInfo.php line 0

public THybridDoc $hybriddoc

$image

File: Base.php line 778

public Import $image

$importer

File: Tcpdf.php line 0

public ImporterInterface|null $importer

$isunicode

File: MetaInfo.php line 0

public bool $isunicode

$keywords

File: MetaInfo.php line 0

public string $keywords

$lang

File: Tcpdf.php line 0

public array<string, string> $lang

$markupFile

File: Base.php line 742

public File $markupFile

$objid

File: MetaInfo.php line 0

public array<string, mixed> $objid

$outlines

File: Tcpdf.php line 0

public array<int, array<string, mixed>> $outlines

$page

File: Base.php line 763

public Page $page

$pdfa

File: MetaInfo.php line 0

public int $pdfa

$pdfaConformance

File: MetaInfo.php line 0

public string $pdfaConformance

$pdffilename

File: Tcpdf.php line 0

public string $pdffilename

$pdfuaMode

File: MetaInfo.php line 0

public string $pdfuaMode

$pdfver

File: MetaInfo.php line 0

public string $pdfver

$pdfx

File: MetaInfo.php line 0

public bool $pdfx

$pdfxMode

File: MetaInfo.php line 0

public string $pdfxMode

$pon

File: MetaInfo.php line 0

public int $pon

$producersuffix

File: MetaInfo.php line 0

public string $producersuffix

$rtl

File: MetaInfo.php line 0

public bool $rtl

$sigapp

File: Tcpdf.php line 0

public bool $sigapp

$sign

File: Tcpdf.php line 0

public bool $sign

$signature

File: Tcpdf.php line 0

public TSignature $signature

$sigtimestamp

File: Tcpdf.php line 0

public TSignTimeStamp $sigtimestamp

$sRGB

File: MetaInfo.php line 0

public bool $sRGB

$subject

File: MetaInfo.php line 0

public string $subject

$subsetfont

File: Tcpdf.php line 0

public bool $subsetfont

$title

File: MetaInfo.php line 0

public string $title

$uniconv

File: Base.php line 758

public Convert $uniconv

$unit

File: Tcpdf.php line 0

public string $unit

$userrights

File: Tcpdf.php line 0

public TUserRights $userrights

$version

File: MetaInfo.php line 0

public string $version

$viewerpref

File: MetaInfo.php line 0

public array<string, mixed> $viewerpref

$xobjects

File: Tcpdf.php line 0

public array<string, mixed> $xobjects

Methods

__construct()

File: Tcpdf.php line 150

public __construct([string|Unit $unit = 'mm' ][, bool $isunicode = true ][, bool $subsetfont = false ][, bool $compress = true ][, string|PdfConformance $mode = '' ][, Encrypt|null $objEncrypt = null ][, TFileOptions|null $fileOptions = null ][, CacheInterface|null $cache = null ]) : mixed

Parameters

  • $unit : string|Unit = ‘mm’: Unit of measure (‘pt’, ‘mm’, ‘cm’, ‘in’) or a Unit enum case.
  • $isunicode : bool = true: True if the document is in Unicode mode.
  • $subsetfont : bool = false: If true subset the embedded fonts to remove the unused characters.
  • $compress : bool = true: Set to false to disable stream compression.
  • $mode : string|PdfConformance = ‘’: PDF mode: “pdfa1”, “pdfa2”, “pdfa3”, “pdfx”, “pdfx1a”, “pdfx3”, “pdfx4”, “pdfx5”, “pdfua”, “pdfua1”, “pdfua2”, empty, or a PdfConformance case.
  • $objEncrypt : Encrypt|null = null: Encryption object. Ignored in PDF/A mode, which forbids encryption.
  • $fileOptions : TFileOptions|null = null: Optional configuration for the shared file helper used to load external resources (images, fonts, SVG, etc.). Supported keys: - allowedHosts (string[]): Whitelist of host names that the library is allowed to fetch over HTTP/HTTPS. For security reasons remote URL loading is DISABLED by default; you MUST populate this list (for example [’example.com’, ‘cdn.example.com’]) to enable any remote download. Local file paths are not affected. - maxRemoteSize (int): Maximum size in bytes accepted for a remote download (default 52428800 = 50 MiB). - curlopts (array<int,bool|int|string>): Per-request cURL options merged on top of the defaults (keys are CURLOPT_* constants). - defaultCurlOpts (array<int,bool|int|string>): Replaces the built-in default cURL options. Use with care; omit to keep the safe defaults. - fixedCurlOpts (array<int,bool|int|string>): cURL options that are always enforced and cannot be overridden by curlopts (for example to pin TLS settings). - allowedPaths (string[]): Trusted local path prefixes for file:// reads. Defaults are automatically computed from the package location to cover bundled example assets.
  • $cache : CacheInterface|null = null: Optional external cache reused by every cacheable sub-library (font subsets, images, …). Implement Com\Tecnick\Pdf\Cache\CacheInterface to bridge your own backend (filesystem, APCu, Redis, PSR-16, …); the application owns the backend, its (de)serialization, expiration and size limits. Null (default) disables external caching. No backend is shipped.

Tags

  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: RandomException

addArtifactContent()

File: Text.php line 1036

public addArtifactContent(string $content, int $pid[, string $type = '' ][, string $subtype = '' ]) : void

This is the preferred API for decorative graphics and page furniture because it writes the wrapped content directly to the selected page.

Parameters

  • $content : string: Raw PDF operators to wrap.
  • $pid : int: Page index.
  • $type : string = ‘’: Optional Artifact /Type (for example ‘Pagination’).
  • $subtype : string = ‘’: Optional Artifact /Subtype (for example ‘Header’ or ‘Footer’).

Tags

  • throws: Exception

addContentAsEmbeddedFile()

File: JavaScript.php line 772

public addContentAsEmbeddedFile(string $file, string $content[, string $mime = 'application/octet-stream' ][, string|AFRelationship $afrel = 'Source' ][, string $desc = '' ]) : void

If a file with the same name already exists, it will be ignored.

Parameters

  • $file : string: File name to be used a key for the embedded file.
  • $content : string: Content of the embedded file.
  • $mime : string = ‘application/octet-stream’: MIME type of the file (e.g., ‘application/xml’).
  • $afrel : string|AFRelationship = ‘Source’: AFRelationship value (Source, Data, Alternative, Supplement, Unspecified) or enum.
  • $desc : string = ‘’: Optional description of the file.

Tags

addEmbeddedFile()

File: JavaScript.php line 721

public addEmbeddedFile(string $file[, string $mime = 'application/octet-stream' ][, string|AFRelationship $afrel = 'Source' ][, string $desc = '' ]) : void

If a file with the same name already exists, it will be ignored.

Parameters

  • $file : string: File name (absolute or relative path).
  • $mime : string = ‘application/octet-stream’: MIME type of the file (e.g., ‘application/xml’).
  • $afrel : string|AFRelationship = ‘Source’: AFRelationship value (Source, Data, Alternative, Supplement, Unspecified) or enum.
  • $desc : string = ‘’: Optional description of the file.

Tags

addEmptySignatureAppearance()

File: Tcpdf.php line 1130

public addEmptySignatureAppearance([float $posx = 0 ][, float $posy = 0 ][, float $width = 0 ][, float $height = 0 ][, int $page = -1 ][, string $name = '' ][, string $description = '' ]) : void

Parameters

  • $posx : float = 0: Abscissa of the upper-left corner.
  • $posy : float = 0: Ordinate of the upper-left corner.
  • $width : float = 0: Width of the signature area.
  • $height : float = 0: Height of the signature area.
  • $page : int = -1: optional page number (if < 0 the current page is used).
  • $name : string = ‘’: Name of the signature.
  • $description : string = ‘’: Description of the field, written as /TU in a tagged mode.

Tags

  • throws: Exception Also available through the fluent API: signature()->emptyField().

addFFButton()

File: JavaScript.php line 1501

public addFFButton(string $name, float $posx, float $posy, float $width, float $height, string $caption, string|array<string, mixed> $action[, TAnnotOpts $opt = ['subtype' => 'Widget'] ][, array<string, mixed> $jsp = [] ]) : int

Parameters

  • $name : string: field name.
  • $posx : float: horizontal position in user units (LTR).
  • $posy : float: vertical position in user units (LTR).
  • $width : float: width in user units.
  • $height : float: height in user units.
  • $caption : string: caption.
  • $action : string|array<string, mixed>: action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as in section 12.7.5 of PDF32000_2008.
  • $opt : TAnnotOpts = [‘subtype’ => ‘Widget’]: Array of options (Annotation Types) - all lowercase.
  • $jsp : array<string, mixed> = []: javascript field properties (see: Javascript for Acrobat API reference).

Tags

  • throws: Exception in case of error.
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception

Return values

int —

PDF Object ID.

addFFCheckBox()

File: JavaScript.php line 1662

public addFFCheckBox(string $name, float $posx, float $posy, float $width[, string $onvalue = 'Yes' ][, bool $checked = false ][, TAnnotOpts $opt = ['subtype' => 'Widget'] ][, array<string, mixed> $jsp = [] ]) : int

Parameters

  • $name : string: field name.
  • $posx : float: horizontal position in user units (LTR).
  • $posy : float: vertical position in user units (LTR).
  • $width : float: width in user units.
  • $onvalue : string = ‘Yes’: Value to be returned if selected.
  • $checked : bool = false: Define the initial state.
  • $opt : TAnnotOpts = [‘subtype’ => ‘Widget’]: Array of options (Annotation Types) - all lowercase.
  • $jsp : array<string, mixed> = []: javascript field properties (see: Javascript for Acrobat API reference).

Tags

  • throws: Exception in case of error.
  • throws: Exception
  • throws: Exception
  • throws: Exception

Return values

int —

PDF Object ID.

addFFComboBox()

File: JavaScript.php line 1739

public addFFComboBox(string $name, float $posx, float $posy, float $width, float $height, array<string|int, array{string, string}>|array<string|int, string> $values[, TAnnotOpts $opt = ['subtype' => 'Widget'] ][, array<string, mixed> $jsp = [] ]) : int

Parameters

  • $name : string: field name.
  • $posx : float: horizontal position in user units (LTR).
  • $posy : float: vertical position in user units (LTR).
  • $width : float: width in user units.
  • $height : float: height in user units.
  • $values : array<string|int, array{string, string}>|array<string|int, string>: List of selection values.
  • $opt : TAnnotOpts = [‘subtype’ => ‘Widget’]: Array of options (Annotation Types) - all lowercase.
  • $jsp : array<string, mixed> = []: javascript field properties (see: Javascript for Acrobat API reference).

Tags

  • throws: Exception in case of error.
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception

Return values

int —

PDF Object ID.

addFFListBox()

File: JavaScript.php line 1812

public addFFListBox(string $name, float $posx, float $posy, float $width, float $height, array<string|int, array{string, string}>|array<string|int, string> $values[, TAnnotOpts $opt = ['subtype' => 'Widget'] ][, array<string, mixed> $jsp = [] ]) : int

Parameters

  • $name : string: field name.
  • $posx : float: horizontal position in user units (LTR).
  • $posy : float: vertical position in user units (LTR).
  • $width : float: width in user units.
  • $height : float: height in user units.
  • $values : array<string|int, array{string, string}>|array<string|int, string>: List of selection values.
  • $opt : TAnnotOpts = [‘subtype’ => ‘Widget’]: Array of options (Annotation Types) - all lowercase.
  • $jsp : array<string, mixed> = []: javascript field properties (see: Javascript for Acrobat API reference).

Tags

  • throws: Exception in case of error.
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception

Return values

int —

PDF Object ID.

addFFRadioButton()

File: JavaScript.php line 1882

public addFFRadioButton(string $name, float $posx, float $posy, float $width[, string $onvalue = 'On' ][, bool $checked = false ][, TAnnotOpts $opt = ['subtype' => 'Widget'] ][, array<string, mixed> $jsp = [] ]) : int

Parameters

  • $name : string: field name.
  • $posx : float: horizontal position in user units (LTR).
  • $posy : float: vertical position in user units (LTR).
  • $width : float: width in user units.
  • $onvalue : string = ‘On’: Value to be returned if selected.
  • $checked : bool = false: Define the initial state.
  • $opt : TAnnotOpts = [‘subtype’ => ‘Widget’]: Array of options (Annotation Types) - all lowercase.
  • $jsp : array<string, mixed> = []: javascript field properties (see: Javascript for Acrobat API reference).

Tags

  • throws: Exception in case of error.
  • throws: Exception
  • throws: Exception
  • throws: Exception

Return values

int —

PDF Object ID.

addFFText()

File: JavaScript.php line 1982

public addFFText(string $name, float $posx, float $posy, float $width, float $height[, TAnnotOpts $opt = ['subtype' => 'text'] ][, array<string, mixed> $jsp = [] ]) : int

Parameters

  • $name : string: field name.
  • $posx : float: horizontal position in user units (LTR).
  • $posy : float: vertical position in user units (LTR).
  • $width : float: width in user units.
  • $height : float: height in user units.
  • $opt : TAnnotOpts = [‘subtype’ => ’text’]: Array of options (Annotation Types) - all lowercase.
  • $jsp : array<string, mixed> = []: javascript field properties (see: Javascript for Acrobat API reference).

Tags

  • throws: Exception in case of error.
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception
  • throws: Exception

Return values

int —

PDF Object ID.

addGlobalCSS()

File: CSS.php line 223

public addGlobalCSS(string $css) : void

Parameters

  • $css : string: CSS content without surrounding