Class TCPDF

Description

This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.

This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).
This version contains some changes: [porting to PHP4, support for UTF-8 Unicode, code style and formatting, php documentation (www.phpdoc.org), ISO page formats, minor improvements, image scale factor]
TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).
To add your own TTF fonts please read /fonts/README.TXT

Located in /tcpdf.php (line 88)


	
			
Variable Summary
author $author
automatic $AutoPageBreak
Bold $b
Barcode $barcode
page $bMargin
buffer $buffer
cell $cMargin
indicates $ColorFlag
compression $compress
array $CoreFonts
creator $creator
current $CurOrientation
current $CurrentFont
default $DefOrientation
array $diffs
commands $DrawColor
default $encoding
height $fh
height $fhPt
commands $FillColor
current $FontFamily
array $FontFiles
HTML $fontList
array $fonts
current $FontSize
current $FontSizePt
current $FontStyle
Footer $footer_font
Minimum $footer_margin
width $fw
width $fwPt
current $h
Header $header_font
Header $header_logo
Minimum $header_margin
String $header_title
Header $header_width
current $hPt
HTML $HREF
Italic $i
array $images
image $imgscale
right-bottom $img_rb_x
right-bottom $img_rb_y
flag $InFooter
HTML $issetfont
boolean $isunicode
scale $k
keywords $keywords
Language $l
height $lasth
layout $LayoutMode
line $LineWidth
array $links
spacer $lispacer
HTML $listcount
left $lMargin
current $n
array $offsets
current $page
threshold $PageBreakTrigger
array $PageLinks
array $pages
right $rMargin
current $state
subject $subject
HTML $tdalign
HTML $tdbegin
HTML $tdbgcolor
HTML $tdheight
HTML $tdwidth
commands $TextColor
title $title
top $tMargin
Underlined $u
underlining $underline
current $w
current $wPt
word $ws
current $x
current $y
zoom $ZoomMode
Method Summary
TCPDF TCPDF ([string $orientation = 'P'], [string $unit = 'mm'], [mixed $format = 'A4'], [boolean $unicode = true], [String $encoding = "UTF-8"])
boolean AcceptPageBreak ()
void AddFont (string $family, [string $style = ''], [string $file = ''])
void addHtmlLink (string $url, string $name, int $fill)
void AddLink ()
void AddPage ([string $orientation = ''])
void AliasNbPages ([string $alias = '{nb}'])
void Cell (float $w, float $h, [string $txt = ''], mixed $border, int $ln, [string $align = ''], int $fill, [mixed $link = ''])
void Close ()
void closedHTMLTagHandler (string $tag)
array convertColorHexToDec ([string $color = "#000000"])
void Error (string $msg)
void Footer ()
float getImageScale ()
int getPageHeight ()
int getPageWidth ()
void getPDFData ()
int GetStringWidth (string $s)
float GetX ()
float GetY ()
void Header ()
void Image (string $file, float $x, float $y, float $w, float $h, [string $type = ''], [mixed $link = ''])
void Line (float $x1, float $y1, float $x2, float $y2)
void Link (float $x, float $y, float $w, float $h, mixed $link)
void Ln ([float $h = ''])
void MultiCell (float $w, float $h, string $txt, mixed $border, [string $align = 'J'], int $fill)
void Open ()
void openHTMLTagHandler (string $tag, string $attr, int $fill)
void Output ([string $name = ''], [string $dest = ''])
int PageNo ()
float pixelsToMillimeters (int $px)
void Rect (float $x, float $y, float $w, float $h, [string $style = ''])
void SetAuthor (string $author)
void SetAutoPageBreak (boolean $auto, float $margin)
void setBarcode ([string $bc = ""])
void SetCompression (boolean $compress)
void SetCreator (string $creator)
void SetDisplayMode (mixed $zoom, [string $layout = 'continuous'])
void SetDrawColor (int $r, [int $g = -1], [int $b = -1])
void SetFillColor (int $r, [int $g = -1], [int $b = -1], [boolean $storeprev = false])
void SetFont (string $family, [string $style = ''], float $size)
void SetFontSize (float $size)
void setFooterFont (array $font)
void setFooterMargin ([int $fm = 10])
void setHeaderData ([string $ln = ""], string $lw, [string $ht = ""], [string $hs = ""])
void setHeaderFont (array $font)
void setHeaderMargin ([int $hm = 10])
void setImageScale (float $scale)
void SetKeywords (string $keywords)
void setLanguageArray (array $language)
void SetLeftMargin (float $margin)
void SetLineWidth (float $width)
void SetLink (int $link, float $y, [int $page = -1])
void SetMargins (float $left, float $top, [float $right = -1])
void SetRightMargin (float $margin)
void setStyle (string $tag, boolean $enable)
void SetSubject (string $subject)
void SetTextColor (int $r, [int $g = -1], [int $b = -1], [boolean $storeprev = false])
void SetTitle (string $title)
void SetTopMargin (float $margin)
void SetX (float $x)
void SetXY (float $x, float $y)
void SetY (float $y)
void Text (float $x, float $y, string $txt)
string unhtmlentities ($text_to_convert $text_to_convert)
array UTF8StringToArray (string $str)
string UTF8ToUTF16BE (string $str, [boolean $setbom = true])
void Write (float $h, string $txt, [mixed $link = ''], int $fill)
void writeBarcode (int $x, int $y, int $w, int $h, string $type, string $style, string $font, int $xres, string $code)
void writeHTML (string $html, [boolean $ln = true], int $fill)
void writeHTMLCell (float $w, float $h, float $x, float $y, [string $html = ''], mixed $border, int $ln, int $fill)
void _begindoc ()
void _beginpage (mixed $orientation)
void _dochecks ()
void _dounderline (mixed $x, mixed $y, mixed $txt)
void _enddoc ()
void _endpage ()
void _escape (mixed $s)
void _escapetext (mixed $s)
void _freadint (mixed $f)
void _getfontpath ()
void _newobj ()
void _out (mixed $s)
void _parsejpg (mixed $file)
void _parsepng (mixed $file)
void _putcatalog ()
void _putfonts ()
void _putheader ()
void _putimages ()
void _putinfo ()
void _putpages ()
void _putresources ()
void _putstream (mixed $s)
void _puttrailer ()
void _puttruetypeunicode (mixed $font)
void _putxobjectdict ()
void _textstring (mixed $s)
Variables
alias $AliasNbPages (line 431)
  • var: for total number of pages
  • access: protected
author $author (line 413)
  • access: protected
automatic $AutoPageBreak (line 371)
  • var: page breaking
  • access: protected
Bold $b (line 658)
  • var: font style status.
  • access: private
Barcode $barcode = false (line 523)
  • var: to print on page footer (only if set).
  • access: private
page $bMargin (line 227)
  • var: break margin
  • access: protected
buffer $buffer (line 113)
  • var: holding in-memory PDF
  • access: protected
cell $cMargin (line 233)
  • var: margin
  • access: protected
indicates $ColorFlag (line 359)
  • var: whether fill and text colors are different
  • access: protected
compression $compress (line 131)
  • var: flag
  • access: protected
array $CoreFonts (line 263)
  • var: of standard font names
  • access: protected
creator $creator (line 425)
  • access: protected
current $CurOrientation (line 143)
  • var: orientation
  • access: protected
current $CurrentFont (line 323)
  • var: font info
  • access: protected
Default $default_table_columns = 4 (line 571)
  • var: number of columns for html table.
  • access: private
default $DefOrientation (line 137)
  • var: orientation
  • access: protected
array $diffs (line 281)
  • var: of encoding differences
  • access: protected
commands $DrawColor (line 341)
  • var: for drawing color
  • access: protected
default $encoding = "UTF-8" (line 683)
  • var: encoding
  • since: 1.53.0.TC010
  • access: private
height $fh (line 179)
  • var: of page format in user unit
  • access: protected
height $fhPt (line 167)
  • var: of page format in points
  • access: protected
commands $FillColor (line 347)
  • var: for filling color
  • access: protected
current $FontFamily (line 305)
  • var: font family
  • access: protected
array $FontFiles (line 275)
  • var: of font files
  • access: protected
HTML $fontList (line 586)
  • var: PARSER: store font list.
  • access: private
array $fonts (line 269)
  • var: of used fonts
  • access: protected
current $FontSize (line 335)
  • var: font size in user unit
  • access: protected
current $FontSizePt (line 329)
  • var: font size in points
  • access: protected
current $FontStyle (line 311)
  • var: font style
  • access: protected
Footer $footer_font (line 511)
  • var: font.
  • access: private
Minimum $footer_margin (line 485)
  • var: distance between footer and bottom page margin.
  • access: private
width $fw (line 173)
  • var: of page format in user unit
  • access: protected
width $fwPt (line 161)
  • var: of page format in points
  • access: protected
current $h (line 203)
  • var: height of page in user unit
  • access: protected
Header $header_font (line 505)
  • var: font.
  • access: private
Header $header_logo = "" (line 547)
  • var: image logo.
  • access: private
Header $header_logo_width = 30 (line 553)
  • var: image logo width in mm.
  • access: private
Minimum $header_margin (line 479)
  • var: distance between header and top page margin.
  • access: private
String $header_string = "" (line 565)
  • var: to print on document header.
  • access: private
String $header_title = "" (line 559)
  • var: to print as title on document header.
  • access: private
Header $header_width = 0 (line 541)
  • var: width (0 = full page width).
  • access: private
current $hPt (line 191)
  • var: height of page in points
  • access: protected
HTML $HREF (line 580)
  • var: PARSER: store current link.
  • access: private
Italic $i (line 670)
  • var: font style status.
  • access: private
array $images (line 287)
  • var: of used images
  • access: protected
image $imgscale = 1 (line 455)
  • var: scale factor
  • access: protected
  • author: Nicola Asuni
  • since: 2004-06-14
right-bottom $img_rb_x (line 439)
  • var: corner X coordinate of inserted image
  • access: protected
  • author: Nicola Asuni
  • since: 2002-07-31
right-bottom $img_rb_y (line 447)
  • var: corner Y coordinate of inserted image
  • access: protected
  • author: Nicola Asuni
  • since: 2002-07-31
flag $InFooter (line 383)
  • var: set when processing footer
  • access: protected
PHP $internal_encoding (line 690)
  • var: internal encoding
  • since: 1.53.0.TC016
  • access: private
HTML $issetcolor (line 598)
  • var: PARSER: true when color attribute is set.
  • access: private
HTML $issetfont (line 592)
  • var: PARSER: true when font attribute is set.
  • access: private
boolean $isunicode = false (line 463)
  • var: set to true when the input text is unicode (require unicode fonts)
  • access: protected
  • author: Nicola Asuni
  • since: 2005-01-02
scale $k (line 155)
  • var: factor (number of points in user unit)
  • access: protected
keywords $keywords (line 419)
  • access: protected
Language $l (line 517)
  • var: templates.
  • access: private
height $lasth (line 251)
  • var: of last cell printed
  • access: protected
layout $LayoutMode (line 395)
  • var: display mode
  • access: protected
line $LineWidth (line 257)
  • var: width in user unit
  • access: protected
array $links (line 299)
  • var: of internal links
  • access: protected
spacer $lispacer = "" (line 676)
  • var: for LI tags.
  • access: private
HTML $listcount = 0 (line 610)
  • var: PARSER: count list items.
  • access: private
HTML $listordered = false (line 604)
  • var: PARSER: true in case of ordered list (OL), false otherwise.
  • access: private
left $lMargin (line 209)
  • var: margin
  • access: protected
current $n (line 101)
  • var: object number
  • access: protected
array $offsets (line 107)
  • var: of object offsets
  • access: protected
array $OrientationChanges (line 149)
  • var: indicating orientation changes
  • access: protected
original $original_lMargin (line 492)
  • var: left margin value
  • since: 1.53.0.TC013
  • access: private
original $original_rMargin (line 499)
  • var: right margin value
  • since: 1.53.0.TC013
  • access: private
current $page (line 95)
  • var: page number
  • access: protected
threshold $PageBreakTrigger (line 377)
  • var: used to trigger page breaks
  • access: protected
array $PageLinks (line 293)
  • var: of links in pages
  • access: protected
array $pages (line 119)
  • var: containing pages
  • access: protected
PDF $PDFVersion = "1.3" (line 470)
  • var: version
  • access: protected
  • since: 1.5.3
store $prevFillColor = array(255,255,255) (line 697)
  • var: previous fill color as RGB array
  • since: 1.53.0.TC017
  • access: private
store $prevFontFamily (line 711)
  • var: previous font family
  • since: 1.53.0.TC017
  • access: private
store $prevFontStyle (line 718)
  • var: previous font style
  • since: 1.53.0.TC017
  • access: private
store $prevTextColor = array(0,0,0) (line 704)
  • var: previous text color as RGB array
  • since: 1.53.0.TC017
  • access: private
If $print_footer = true (line 535)
  • var: true prints footer.
  • access: private
If $print_header = true (line 529)
  • var: true prints header
  • access: private
right $rMargin (line 221)
  • var: margin
  • access: protected
current $state (line 125)
  • var: document state
  • access: protected
subject $subject (line 407)
  • access: protected
HTML $tableborder = 0 (line 616)
  • var: PARSER: size of table border.
  • access: private
HTML $tdalign = "L" (line 640)
  • var: PARSER: table align.
  • access: private
HTML $tdbegin = false (line 622)
  • var: PARSER: true at the beginning of table.
  • access: private
HTML $tdbgcolor = false (line 646)
  • var: PARSER: table background color.
  • access: private
HTML $tdheight = 0 (line 634)
  • var: PARSER: table height.
  • access: private
HTML $tdwidth = 0 (line 628)
  • var: PARSER: table width.
  • access: private
Store $tempfontsize = 10 (line 652)
  • var: temporary font size in points.
  • access: private
commands $TextColor (line 353)
  • var: for text color
  • access: protected
title $title (line 401)
  • access: protected
top $tMargin (line 215)
  • var: margin
  • access: protected
Underlined $u (line 664)
  • var: font style status.
  • access: private
underlining $underline (line 317)
  • var: flag
  • access: protected
current $w (line 197)
  • var: width of page in user unit
  • access: protected
current $wPt (line 185)
  • var: width of page in points
  • access: protected
word $ws (line 365)
  • var: spacing
  • access: protected
current $x (line 239)
  • var: horizontal position in user unit for cell positioning
  • access: protected
current $y (line 245)
  • var: vertical position in user unit for cell positioning
  • access: protected
zoom $ZoomMode (line 389)
  • var: display mode
  • access: protected
Methods
Constructor TCPDF (line 735)

This is the class constructor.

It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).

  • since: 1.0
TCPDF TCPDF ([string $orientation = 'P'], [string $unit = 'mm'], [mixed $format = 'A4'], [boolean $unicode = true], [String $encoding = "UTF-8"])
  • string $orientation: page orientation. Possible values are (case insensitive):
    • P or Portrait (default)
    • L or Landscape
  • string $unit: User measure unit. Possible values are:
    • pt: point
    • mm: millimeter (default)
    • cm: centimeter
    • in: inch

    A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  • mixed $format: The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).
    • 4A0
    • 2A0
    • A0
    • A1
    • A2
    • A3
    • A4 (default)
    • A5
    • A6
    • A7
    • A8
    • A9
    • A10
    • B0
    • B1
    • B2
    • B3
    • B4
    • B5
    • B6
    • B7
    • B8
    • B9
    • B10
    • C0
    • C1
    • C2
    • C3
    • C4
    • C5
    • C6
    • C7
    • C8
    • C9
    • C10
    • RA0
    • RA1
    • RA2
    • RA3
    • RA4
    • SRA0
    • SRA1
    • SRA2
    • SRA3
    • SRA4
    • LETTER
    • LEGAL
    • EXECUTIVE
    • FOLIO
  • boolean $unicode: TRUE means that the input text is unicode (default = true)
  • String $encoding: charset encoding; default is UTF-8
AcceptPageBreak (line 1927)

Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by SetAutoPageBreak().

This method is called automatically and should not be called directly by the application.
Example:
The method is overriden in an inherited class in order to obtain a 3 column layout:

 class PDF extends TCPDF {
 	var $col=0;

 	function SetCol($col) {
 		//Move position to a column
 		$this->col=$col;
 		$x=10+$col*65;
 		$this->SetLeftMargin($x);
 		$this->SetX($x);
 	}

 	function AcceptPageBreak() {
 		if($this->col<2) {
 			//Go to next column
 			$this->SetCol($this->col+1);
 			$this->SetY(10);
 			return false;
 		}
 		else {
 			//Go back to first column and issue page break
 			$this->SetCol(0);
 			return true;
 		}
 	}
 }

 $pdf=new PDF();
 $pdf->Open();
 $pdf->AddPage();
 $pdf->SetFont('Arial','',12);
 for($i=1;$i<=300;$i++) {
     $pdf->Cell(0,5,"Line $i",0,1);
 }
 $pdf->Output();

boolean AcceptPageBreak ()
AddFont (line 1605)

Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility. The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by FPDF_FONTPATH if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.

Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]. Example:

 $pdf->AddFont('Comic','I');
 // is equivalent to:
 $pdf->AddFont('Comic','I','comici.php');

void AddFont (string $family, [string $style = ''], [string $file = ''])
  • string $family: Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  • string $style: Font style. Possible values are (case insensitive):
    • empty string: regular (default)
    • B: bold
    • I: italic
    • BI or IB: bold italic