Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: com-tecnick-tcpdf

License

Content on this site is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5. Some parts of this website may be subject to other licenses.

 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/tcpdf.php (line 87)

Class TCPDF
Variable Summary
Variable author $author
Variable automatic $AutoPageBreak
Variable page $bMargin
Variable buffer $buffer
Variable cell $cMargin
Variable indicates $ColorFlag
Variable compression $compress
Variable array $CoreFonts
Variable creator $creator
Variable current $CurOrientation
Variable current $CurrentFont
Variable default $DefOrientation
Variable array $diffs
Variable commands $DrawColor
Variable height $fh
Variable height $fhPt
Variable commands $FillColor
Variable current $FontFamily
Variable array $FontFiles
Variable array $fonts
Variable current $FontSize
Variable current $FontSizePt
Variable current $FontStyle
Variable width $fw
Variable width $fwPt
Variable current $h
Variable current $hPt
Variable array $images
Variable image $imgscale
Variable right-bottom $img_rb_x
Variable right-bottom $img_rb_y
Variable flag $InFooter
Variable boolean $isunicode
Variable scale $k
Variable keywords $keywords
Variable height $lasth
Variable layout $LayoutMode
Variable line $LineWidth
Variable array $links
Variable left $lMargin
Variable current $n
Variable array $offsets
Variable current $page
Variable threshold $PageBreakTrigger
Variable array $PageLinks
Variable array $pages
Variable right $rMargin
Variable current $state
Variable subject $subject
Variable commands $TextColor
Variable title $title
Variable top $tMargin
Variable underlining $underline
Variable current $w
Variable current $wPt
Variable word $ws
Variable current $x
Variable current $y
Variable zoom $ZoomMode
Method Summary
Constructor TCPDF TCPDF ([string $orientation = 'P'], [string $unit = 'mm'], [mixed $format = 'A4'], [boolean $unicode = true], [String $encoding = "UTF-8"])
Method boolean AcceptPageBreak ()
Method void AddFont (string $family, [string $style = ''], [string $file = ''])
Method void addHtmlLink (string $url, string $name, [int $fill = 0])
Method void AddLink ()
Method void AddPage ([string $orientation = ''])
Method void AliasNbPages ([string $alias = '{nb}'])
Method void Cell (float $w, [float $h = 0], [string $txt = ''], [mixed $border = 0], [int $ln = 0], [string $align = ''], [int $fill = 0], [mixed $link = ''])
Method void Close ()
Method void Error (string $msg)
Method void Footer ()
Method float getImageScale ()
Method int getPageHeight ()
Method int getPageWidth ()
Method void getPDFData ()
Method int GetStringWidth (string $s)
Method float GetX ()
Method float GetY ()
Method void Header ()
Method void Image (string $file, float $x, float $y, [float $w = 0], [float $h = 0], [string $type = ''], [mixed $link = ''])
Method string justify ($rowWidth $rowWidth, $txtWidth $txtWidth, $spaceWidth $spaceWidth, $txt $txt)
Method void Line (float $x1, float $y1, float $x2, float $y2)
Method void Link (float $x, float $y, float $w, float $h, mixed $link)
Method void Ln ([float $h = ''])
Method int MultiCell (float $w, float $h, string $txt, [mixed $border = 0], [string $align = 'J'], [int $fill = 0], [int $ln = 1])
Method void Open ()
Method void Output ([string $name = ''], [string $dest = ''])
Method int PageNo ()
Method void Rect (float $x, float $y, float $w, float $h, [string $style = ''])
Method void SetAuthor (string $author)
Method void SetAutoPageBreak (boolean $auto, [float $margin = 0])
Method void setBarcode ([string $bc = ""])
Method void SetCompression (boolean $compress)
Method void SetCreator (string $creator)
Method void SetDisplayMode (mixed $zoom, [string $layout = 'continuous'])
Method void SetDrawColor (int $r, [int $g = -1], [int $b = -1])
Method void SetFillColor (int $r, [int $g = -1], [int $b = -1], [boolean $storeprev = false])
Method void SetFont (string $family, [string $style = ''], [float $size = 0])
Method void SetFontSize (float $size)
Method void setFooterFont (array $font)
Method void setFooterMargin ([int $fm = 10])
Method void setHeaderData ([string $ln = ""], [string $lw = 0], [string $ht = ""], [string $hs = ""])
Method void setHeaderFont (array $font)
Method void setHeaderMargin ([int $hm = 10])
Method void setImageScale (float $scale)
Method void SetKeywords (string $keywords)
Method void setLanguageArray (array $language)
Method void setLastH (float $h)
Method void SetLeftMargin (float $margin)
Method void SetLineWidth (float $width)
Method void SetLink (int $link, [float $y = 0], [int $page = -1])
Method void SetMargins (float $left, float $top, [float $right = -1])
Method void setPrintFooter ([ $val = true], boolean $value)
Method void setPrintHeader ([boolean $val = true])
Method void SetRightMargin (float $margin)
Method void SetSubject (string $subject)
Method void SetTextColor (int $r, [int $g = -1], [int $b = -1], [boolean $storeprev = false])
Method void SetTitle (string $title)
Method void SetTopMargin (float $margin)
Method void SetX (float $x)
Method void SetXY (float $x, float $y)
Method void SetY (float $y)
Method void Text (float $x, float $y, string $txt)
Method string unhtmlentities ($text_to_convert $text_to_convert)
Method array UTF8StringToArray (string $str)
Method string UTF8ToUTF16BE (string $str, [boolean $setbom = true])
Method void Write (float $h, string $txt, [mixed $link = ''], [int $fill = 0])
Method void writeBarcode (int $x, int $y, int $w, int $h, string $type, string $style, string $font, int $xres, string $code)
Method void writeHTML (string $html, [boolean $ln = true], [int $fill = 0])
Method void writeHTMLCell (float $w, float $h, float $x, float $y, [string $html = ''], [mixed $border = 0], [int $ln = 0], [int $fill = 0])
Method void _begindoc ()
Method void _beginpage ( $orientation)
Method void _dochecks ()
Method void _dounderline ( $x,  $y,  $txt)
Method void _enddoc ()
Method void _endpage ()
Method void _escape ( $s)
Method void _escapetext ( $s)
Method void _freadint ( $f)
Method void _getfontpath ()
Method void _newobj ()
Method void _out ( $s)
Method void _parsejpg ( $file)
Method void _parsepng ( $file)
Method void _putcatalog ()
Method void _putfonts ()
Method void _putheader ()
Method void _putimages ()
Method void _putinfo ()
Method void _putpages ()
Method void _putresources ()
Method void _putstream ( $s)
Method void _puttrailer ()
Method void _puttruetypeunicode ( $font)
Method void _putxobjectdict ()
Method void _textstring ( $s)
Variables
alias $AliasNbPages (line 430)
  • var: for total number of pages
  • access: protected
author $author (line 412)
  • access: protected
automatic $AutoPageBreak (line 370)
  • var: page breaking
  • access: protected
page $bMargin (line 226)
  • var: break margin
  • access: protected
buffer $buffer (line 112)
  • var: holding in-memory PDF
  • access: protected
cell $cMargin (line 232)
  • var: margin
  • access: protected
indicates $ColorFlag (line 358)
  • var: whether fill and text colors are different
  • access: protected
compression $compress (line 130)
  • var: flag
  • access: protected
array $CoreFonts (line 262)
  • var: of standard font names
  • access: protected
creator $creator (line 424)
  • access: protected
current $CurOrientation (line 142)
  • var: orientation
  • access: protected
current $CurrentFont (line 322)
  • var: font info
  • access: protected
default $DefOrientation (line 136)
  • var: orientation
  • access: protected
array $diffs (line 280)
  • var: of encoding differences
  • access: protected
commands $DrawColor (line 340)
  • var: for drawing color
  • access: protected
height $fh (line 178)
  • var: of page format in user unit
  • access: protected
height $fhPt (line 166)
  • var: of page format in points
  • access: protected
commands $FillColor (line 346)
  • var: for filling color
  • access: protected
current $FontFamily (line 304)
  • var: font family
  • access: protected
array $FontFiles (line 274)
  • var: of font files
  • access: protected
array $fonts (line 268)
  • var: of used fonts
  • access: protected
current $FontSize (line 334)
  • var: font size in user unit
  • access: protected
current $FontSizePt (line 328)
  • var: font size in points
  • access: protected
current $FontStyle (line 310)
  • var: font style
  • access: protected
width $fw (line 172)
  • var: of page format in user unit
  • access: protected
width $fwPt (line 160)
  • var: of page format in points
  • access: protected
current $h (line 202)
  • var: height of page in user unit
  • access: protected
current $hPt (line 190)
  • var: height of page in points
  • access: protected
array $images (line 286)
  • var: of used images
  • access: protected
image $imgscale = 1 (line 454)
  • var: scale factor
  • access: protected
  • author: Nicola Asuni
  • since: 2004-06-14
right-bottom $img_rb_x (line 438)
  • var: corner X coordinate of inserted image
  • access: protected
  • author: Nicola Asuni
  • since: 2002-07-31
right-bottom $img_rb_y (line 446)
  • var: corner Y coordinate of inserted image
  • access: protected
  • author: Nicola Asuni
  • since: 2002-07-31
flag $InFooter (line 382)
  • var: set when processing footer
  • access: protected
boolean $isunicode = false (line 462)
  • 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 154)
  • var: factor (number of points in user unit)
  • access: protected
keywords $keywords (line 418)
  • access: protected
height $lasth (line 250)
  • var: of last cell printed
  • access: protected
layout $LayoutMode (line 394)
  • var: display mode
  • access: protected
line $LineWidth (line 256)
  • var: width in user unit
  • access: protected
array $links (line 298)
  • var: of internal links
  • access: protected
left $lMargin (line 208)
  • var: margin
  • access: protected
current $n (line 100)
  • var: object number
  • access: protected
array $offsets (line 106)
  • var: of object offsets
  • access: protected
array $OrientationChanges (line 148)
  • var: indicating orientation changes
  • access: protected
current $page (line 94)
  • var: page number
  • access: protected
threshold $PageBreakTrigger (line 376)
  • var: used to trigger page breaks
  • access: protected
array $PageLinks (line 292)
  • var: of links in pages
  • access: protected
array $pages (line 118)
  • var: containing pages
  • access: protected
PDF $PDFVersion = "1.3" (line 469)
  • var: version
  • access: protected
  • since: 1.5.3
right $rMargin (line 220)
  • var: margin
  • access: protected
current $state (line 124)
  • var: document state
  • access: protected
subject $subject (line 406)
  • access: protected
commands $TextColor (line 352)
  • var: for text color
  • access: protected
title $title (line 400)
  • access: protected
top $tMargin (line 214)
  • var: margin
  • access: protected
underlining $underline (line 316)
  • var: flag
  • access: protected
current $w (line 196)
  • var: width of page in user unit
  • access: protected
current $wPt (line 184)
  • var: width of page in points
  • access: protected
word $ws (line 364)
  • var: spacing
  • access: protected
current $x (line 238)
  • var: horizontal position in user unit for cell positioning
  • access: protected
current $y (line 244)
  • var: vertical position in user unit for cell positioning
  • access: protected
zoom $ZoomMode (line 388)
  • var: display mode
  • access: protected
Methods
Constructor TCPDF (line 734)

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 1952)

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 1630)

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');