PageRenderTime 62ms CodeModel.GetById 13ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 1ms

/phpmyadmin/libraries/tcpdf/tcpdf.php

https://bitbucket.org/DenizYldrm/openemr
PHP | 4138 lines | 2321 code | 305 blank | 1512 comment | 373 complexity | 0df8deb95a8500375d794023287dd673 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2//============================================================+
   3// File name   : tcpdf.php
   4// Begin       : 2002-08-03
   5// Last Update : 2006-10-27
   6// Author      : Nicola Asuni
   7// Version     : 1.53.0.TC026_PHP4
   8// License     : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
   9//
  10// Description : This is a PHP4 class for generating PDF files 
  11//               on-the-fly without requiring external 
  12//               extensions.
  13//
  14// IMPORTANT:
  15// This class is an extension and improvement of the public Domain 
  16// FPDF class by Olivier Plathey (http://www.fpdf.org).
  17//
  18// Main changes by Nicola Asuni:
  19//    PHP4 porting;
  20//    UTF-8 Unicode support;
  21//    code refactoring;
  22//    source code clean up;
  23//    code style and formatting;
  24//    source code documentation using phpDocumentor (www.phpdoc.org);
  25//    All ISO page formats were included;
  26//    image scale factor;
  27//    includes methods to parse and printsome XHTML code, supporting the following elements: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small;
  28//    includes a method to print various barcode formats using an improved version of "Generic Barcode Render Class" by Karim Mribti (http://www.mribti.com/barcode/) (require GD library: http://www.boutell.com/gd/);
  29//    defines standard Header() and Footer() methods.
  30//============================================================+
  31
  32/**
  33 * include configuration file
  34 */
  35// Disabled in phpMyAdmin
  36//require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  37
  38
  39/**
  40 * TCPDF Class.
  41 * @package com.tecnick.tcpdf
  42 */
  43 
  44/**
  45 * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
  46 * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  47 * <h3>TCPDF main changes from FPDF are:</h3><ul>
  48 * <li>PHP4 porting</li>
  49 * <li>UTF-8 Unicode support</li>
  50 * <li>source code clean up</li>
  51 * <li>code style and formatting</li>
  52 * <li>source code documentation using phpDocumentor (www.phpdoc.org)</li>
  53 * <li>All ISO page formats were included</li>
  54 * <li>image scale factor</li>
  55 * <li>includes methods to parse and printsome XHTML code, supporting the following elements: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small;</li>
  56 * <li>includes a method to print various barcode formats using an improved version of "Generic Barcode Render Class" by Karim Mribti (http://www.mribti.com/barcode/) (require GD library: http://www.boutell.com/gd/)</li>
  57 * <li>defines standard Header() and Footer() methods.</li>
  58 * </ul>
  59 * Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p>
  60 * @name TCPDF
  61 * @package com.tecnick.tcpdf
  62 * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  63 * @author Nicola Asuni
  64 * @copyright 2004-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY - www.tecnick.com - info@tecnick.com
  65 * @link http://tcpdf.sourceforge.net
  66 * @license http://www.gnu.org/copyleft/lesser.html LGPL
  67 @version 1.53.0.TC026_PHP4
  68 */
  69
  70if(!class_exists('TCPDF')) {
  71	/**
  72	 * define default PDF document producer
  73	 */ 
  74	define('PDF_PRODUCER','TCPDF 1.53.0.TC026_PHP4 (http://tcpdf.sourceforge.net)');
  75	
  76	/**
  77	* This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
  78	* This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  79	* 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]<br>
  80	* TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  81	* To add your own TTF fonts please read /fonts/README.TXT
  82	* @name TCPDF
  83	* @package com.tecnick.tcpdf
  84	* @version 1.53.0.TC026_PHP4
  85	* @author Nicola Asuni
  86	* @link http://tcpdf.sourceforge.net
  87	* @license http://www.gnu.org/copyleft/lesser.html LGPL
  88	*/
  89	class TCPDF {
  90		//var properties
  91
  92		/**
  93		* @var current page number
  94		* @access protected
  95		*/
  96		var $page;
  97
  98		/**
  99		* @var current object number
 100		* @access protected
 101		*/
 102		var $n;
 103
 104		/**
 105		* @var array of object offsets
 106		* @access protected
 107		*/
 108		var $offsets;
 109
 110		/**
 111		* @var buffer holding in-memory PDF
 112		* @access protected
 113		*/
 114		var $buffer;
 115
 116		/**
 117		* @var array containing pages
 118		* @access protected
 119		*/
 120		var $pages;
 121
 122		/**
 123		* @var current document state
 124		* @access protected
 125		*/
 126		var $state;
 127
 128		/**
 129		* @var compression flag
 130		* @access protected
 131		*/
 132		var $compress;
 133
 134		/**
 135		* @var default orientation
 136		* @access protected
 137		*/
 138		var $DefOrientation;
 139
 140		/**
 141		* @var current orientation
 142		* @access protected
 143		*/
 144		var $CurOrientation;
 145
 146		/**
 147		* @var array indicating orientation changes
 148		* @access protected
 149		*/
 150		var $OrientationChanges;
 151
 152		/**
 153		* @var scale factor (number of points in user unit)
 154		* @access protected
 155		*/
 156		var $k;
 157
 158		/**
 159		* @var width of page format in points
 160		* @access protected
 161		*/
 162		var $fwPt;
 163
 164		/**
 165		* @var height of page format in points
 166		* @access protected
 167		*/
 168		var $fhPt;
 169
 170		/**
 171		* @var width of page format in user unit
 172		* @access protected
 173		*/
 174		var $fw;
 175
 176		/**
 177		* @var height of page format in user unit
 178		* @access protected
 179		*/
 180		var $fh;
 181
 182		/**
 183		* @var current width of page in points
 184		* @access protected
 185		*/
 186		var $wPt;
 187
 188		/**
 189		* @var current height of page in points
 190		* @access protected
 191		*/
 192		var $hPt;
 193
 194		/**
 195		* @var current width of page in user unit
 196		* @access protected
 197		*/
 198		var $w;
 199
 200		/**
 201		* @var current height of page in user unit
 202		* @access protected
 203		*/
 204		var $h;
 205
 206		/**
 207		* @var left margin
 208		* @access protected
 209		*/
 210		var $lMargin;
 211
 212		/**
 213		* @var top margin
 214		* @access protected
 215		*/
 216		var $tMargin;
 217
 218		/**
 219		* @var right margin
 220		* @access protected
 221		*/
 222		var $rMargin;
 223
 224		/**
 225		* @var page break margin
 226		* @access protected
 227		*/
 228		var $bMargin;
 229
 230		/**
 231		* @var cell margin
 232		* @access protected
 233		*/
 234		var $cMargin;
 235
 236		/**
 237		* @var current horizontal position in user unit for cell positioning
 238		* @access protected
 239		*/
 240		var $x;
 241
 242		/**
 243		* @var current vertical position in user unit for cell positioning
 244		* @access protected
 245		*/
 246		var $y;
 247
 248		/**
 249		* @var height of last cell printed
 250		* @access protected
 251		*/
 252		var $lasth;
 253
 254		/**
 255		* @var line width in user unit
 256		* @access protected
 257		*/
 258		var $LineWidth;
 259
 260		/**
 261		* @var array of standard font names
 262		* @access protected
 263		*/
 264		var $CoreFonts;
 265
 266		/**
 267		* @var array of used fonts
 268		* @access protected
 269		*/
 270		var $fonts;
 271
 272		/**
 273		* @var array of font files
 274		* @access protected
 275		*/
 276		var $FontFiles;
 277
 278		/**
 279		* @var array of encoding differences
 280		* @access protected
 281		*/
 282		var $diffs;
 283
 284		/**
 285		* @var array of used images
 286		* @access protected
 287		*/
 288		var $images;
 289
 290		/**
 291		* @var array of links in pages
 292		* @access protected
 293		*/
 294		var $PageLinks;
 295
 296		/**
 297		* @var array of internal links
 298		* @access protected
 299		*/
 300		var $links;
 301
 302		/**
 303		* @var current font family
 304		* @access protected
 305		*/
 306		var $FontFamily;
 307
 308		/**
 309		* @var current font style
 310		* @access protected
 311		*/
 312		var $FontStyle;
 313
 314		/**
 315		* @var underlining flag
 316		* @access protected
 317		*/
 318		var $underline;
 319
 320		/**
 321		* @var current font info
 322		* @access protected
 323		*/
 324		var $CurrentFont;
 325
 326		/**
 327		* @var current font size in points
 328		* @access protected
 329		*/
 330		var $FontSizePt;
 331
 332		/**
 333		* @var current font size in user unit
 334		* @access protected
 335		*/
 336		var $FontSize;
 337
 338		/**
 339		* @var commands for drawing color
 340		* @access protected
 341		*/
 342		var $DrawColor;
 343
 344		/**
 345		* @var commands for filling color
 346		* @access protected
 347		*/
 348		var $FillColor;
 349
 350		/**
 351		* @var commands for text color
 352		* @access protected
 353		*/
 354		var $TextColor;
 355
 356		/**
 357		* @var indicates whether fill and text colors are different
 358		* @access protected
 359		*/
 360		var $ColorFlag;
 361
 362		/**
 363		* @var word spacing
 364		* @access protected
 365		*/
 366		var $ws;
 367
 368		/**
 369		* @var automatic page breaking
 370		* @access protected
 371		*/
 372		var $AutoPageBreak;
 373
 374		/**
 375		* @var threshold used to trigger page breaks
 376		* @access protected
 377		*/
 378		var $PageBreakTrigger;
 379
 380		/**
 381		* @var flag set when processing footer
 382		* @access protected
 383		*/
 384		var $InFooter;
 385
 386		/**
 387		* @var zoom display mode
 388		* @access protected
 389		*/
 390		var $ZoomMode;
 391
 392		/**
 393		* @var layout display mode
 394		* @access protected
 395		*/
 396		var $LayoutMode;
 397
 398		/**
 399		* @var title
 400		* @access protected
 401		*/
 402		var $title;
 403
 404		/**
 405		* @var subject
 406		* @access protected
 407		*/
 408		var $subject;
 409
 410		/**
 411		* @var author
 412		* @access protected
 413		*/
 414		var $author;
 415
 416		/**
 417		* @var keywords
 418		* @access protected
 419		*/
 420		var $keywords;
 421
 422		/**
 423		* @var creator
 424		* @access protected
 425		*/
 426		var $creator;
 427
 428		/**
 429		* @var alias for total number of pages
 430		* @access protected
 431		*/
 432		var $AliasNbPages;
 433
 434		/**
 435		* @var right-bottom corner X coordinate of inserted image
 436		* @since 2002-07-31
 437		* @author Nicola Asuni
 438		* @access protected
 439		*/
 440		var $img_rb_x;
 441
 442		/**
 443		* @var right-bottom corner Y coordinate of inserted image
 444		* @since 2002-07-31
 445		* @author Nicola Asuni
 446		* @access protected
 447		*/
 448		var $img_rb_y;
 449
 450		/**
 451		* @var image scale factor
 452		* @since 2004-06-14
 453		* @author Nicola Asuni
 454		* @access protected
 455		*/
 456		var $imgscale = 1;
 457
 458		/**
 459		* @var boolean set to true when the input text is unicode (require unicode fonts)
 460		* @since 2005-01-02
 461		* @author Nicola Asuni
 462		* @access protected
 463		*/
 464		var $isunicode = false;
 465
 466		/**
 467		* @var PDF version
 468		* @since 1.5.3
 469		* @access protected
 470		*/
 471		var $PDFVersion = "1.3";
 472		
 473		
 474		// ----------------------
 475		
 476		/**
 477		 * @var Minimum distance between header and top page margin.
 478		 * @access private
 479		 */
 480		var $header_margin;
 481		
 482		/**
 483		 * @var Minimum distance between footer and bottom page margin.
 484		 * @access private
 485		 */
 486		var $footer_margin;
 487		
 488		/**
 489		 * @var original left margin value
 490		 * @access private
 491		 * @since 1.53.0.TC013
 492		 */
 493		var $original_lMargin;
 494		
 495		/**
 496		 * @var original right margin value
 497		 * @access private
 498		 * @since 1.53.0.TC013
 499		 */
 500		var $original_rMargin;
 501			
 502		/**
 503		 * @var Header font.
 504		 * @access private
 505		 */
 506		var $header_font;
 507		
 508		/**
 509		 * @var Footer font.
 510		 * @access private
 511		 */
 512		var $footer_font;
 513		
 514		/**
 515		 * @var Language templates.
 516		 * @access private
 517		 */
 518		var $l;
 519		
 520		/**
 521		 * @var Barcode to print on page footer (only if set).
 522		 * @access private
 523		 */
 524		var $barcode = false;
 525		
 526		/**
 527		 * @var If true prints header
 528		 * @access private
 529		 */
 530		var $print_header = true;
 531		
 532		/**
 533		 * @var If true prints footer.
 534		 * @access private
 535		 */
 536		var $print_footer = true;
 537		
 538		/**
 539		 * @var Header width (0 = full page width).
 540		 * @access private
 541		 */
 542		var $header_width = 0;
 543		
 544		/**
 545		 * @var Header image logo.
 546		 * @access private
 547		 */
 548		var $header_logo = "";
 549		
 550		/**
 551		 * @var Header image logo width in mm.
 552		 * @access private
 553		 */
 554		var $header_logo_width = 30;
 555		
 556		/**
 557		 * @var String to print as title on document header.
 558		 * @access private
 559		 */
 560		var $header_title = "";
 561		
 562		/**
 563		 * @var String to print on document header.
 564		 * @access private
 565		 */
 566		var $header_string = "";
 567		
 568		/**
 569		 * @var Default number of columns for html table.
 570		 * @access private
 571		 */
 572		var $default_table_columns = 4;
 573		
 574		
 575		// variables for html parser
 576		
 577		/**
 578		 * @var HTML PARSER: store current link.
 579		 * @access private
 580		 */
 581		var $HREF;
 582		
 583		/**
 584		 * @var HTML PARSER: store font list.
 585		 * @access private
 586		 */
 587		var $fontList;
 588		
 589		/**
 590		 * @var HTML PARSER: true when font attribute is set.
 591		 * @access private
 592		 */
 593		var $issetfont;
 594		
 595		/**
 596		 * @var HTML PARSER: true when color attribute is set.
 597		 * @access private
 598		 */
 599		var $issetcolor;
 600		
 601		/**
 602		 * @var HTML PARSER: true in case of ordered list (OL), false otherwise.
 603		 * @access private
 604		 */
 605		var $listordered = false;
 606		
 607		/**
 608		 * @var HTML PARSER: count list items.
 609		 * @access private
 610		 */
 611		var $listcount = 0;
 612		
 613		/**
 614		 * @var HTML PARSER: size of table border.
 615		 * @access private
 616		 */
 617		var $tableborder = 0;
 618		
 619		/**
 620		 * @var HTML PARSER: true at the beginning of table.
 621		 * @access private
 622		 */
 623		var $tdbegin = false;
 624		
 625		/**
 626		 * @var HTML PARSER: table width.
 627		 * @access private
 628		 */
 629		var $tdwidth = 0;
 630		
 631		/**
 632		 * @var HTML PARSER: table height.
 633		 * @access private
 634		 */
 635		var $tdheight = 0;
 636		
 637		/**
 638		 * @var HTML PARSER: table align.
 639		 * @access private
 640		 */
 641		var $tdalign = "L";
 642		
 643		/**
 644		 * @var HTML PARSER: table background color.
 645		 * @access private
 646		 */
 647		var $tdbgcolor = false;
 648		
 649		/**
 650		 * @var Store temporary font size in points.
 651		 * @access private
 652		 */
 653		var $tempfontsize = 10;
 654		
 655		/**
 656		 * @var Bold font style status.
 657		 * @access private
 658		 */
 659		var $b;
 660		
 661		/**
 662		 * @var Underlined font style status.
 663		 * @access private
 664		 */
 665		var $u;
 666		
 667		/**
 668		 * @var Italic font style status.
 669		 * @access private
 670		 */
 671		var $i;
 672		
 673		/**
 674		 * @var spacer for LI tags.
 675		 * @access private
 676		 */
 677		var $lispacer = "";
 678		
 679		/**
 680		 * @var default encoding
 681		 * @access private
 682		 * @since 1.53.0.TC010
 683		 */
 684		var $encoding = "UTF-8";
 685		
 686		/**
 687		 * @var PHP internal encoding
 688		 * @access private
 689		 * @since 1.53.0.TC016
 690		 */
 691		var $internal_encoding;
 692		
 693		/**
 694		 * @var store previous fill color as RGB array
 695		 * @access private
 696		 * @since 1.53.0.TC017
 697		 */
 698		var $prevFillColor = array(255,255,255);
 699		
 700		/**
 701		 * @var store previous text color as RGB array
 702		 * @access private
 703		 * @since 1.53.0.TC017
 704		 */
 705		var $prevTextColor = array(0,0,0);
 706		
 707		/**
 708		 * @var store previous font family
 709		 * @access private
 710		 * @since 1.53.0.TC017
 711		 */
 712		var $prevFontFamily;
 713		
 714		/**
 715		 * @var store previous font style
 716		 * @access private
 717		 * @since 1.53.0.TC017
 718		 */
 719		var $prevFontStyle;
 720
 721		//------------------------------------------------------------
 722		// var methods
 723		//------------------------------------------------------------
 724
 725		/**
 726		 * This is the class constructor. 
 727		 * It allows to set up the page format, the orientation and 
 728		 * the measure unit used in all the methods (except for the font sizes).
 729		 * @since 1.0
 730		 * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
 731		 * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />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.
 732		 * @param 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).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
 733		 * @param boolean $unicode TRUE means that the input text is unicode (default = true)
 734		 * @param String $encoding charset encoding; default is UTF-8
 735		 */
 736		function TCPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding="UTF-8") {
 737			
 738			/* Set internal character encoding to ASCII */
 739			if (function_exists("mb_internal_encoding") AND mb_internal_encoding()) {
 740				$this->internal_encoding = mb_internal_encoding();
 741				mb_internal_encoding("ASCII");
 742			}
 743				
 744			//Some checks
 745			$this->_dochecks();
 746			//Initialization of properties
 747			$this->isunicode=$unicode;
 748			$this->page=0;
 749			$this->n=2;
 750			$this->buffer='';
 751			$this->pages=array();
 752			$this->OrientationChanges=array();
 753			$this->state=0;
 754			$this->fonts=array();
 755			$this->FontFiles=array();
 756			$this->diffs=array();
 757			$this->images=array();
 758			$this->links=array();
 759			$this->InFooter=false;
 760			$this->lasth=0;
 761			$this->FontFamily='';
 762			$this->FontStyle='';
 763			$this->FontSizePt=12;
 764			$this->underline=false;
 765			$this->DrawColor='0 G';
 766			$this->FillColor='0 g';
 767			$this->TextColor='0 g';
 768			$this->ColorFlag=false;
 769			$this->ws=0;
 770			//Standard Unicode fonts
 771			$this->CoreFonts=array(
 772			'courier'=>'Courier',
 773			'courierB'=>'Courier-Bold',
 774			'courierI'=>'Courier-Oblique',
 775			'courierBI'=>'Courier-BoldOblique',
 776			'helvetica'=>'Helvetica',
 777			'helveticaB'=>'Helvetica-Bold',
 778			'helveticaI'=>'Helvetica-Oblique',
 779			'helveticaBI'=>'Helvetica-BoldOblique',
 780			'times'=>'Times-Roman',
 781			'timesB'=>'Times-Bold',
 782			'timesI'=>'Times-Italic',
 783			'timesBI'=>'Times-BoldItalic',
 784			'symbol'=>'Symbol',
 785			'zapfdingbats'=>'ZapfDingbats'
 786			);
 787
 788			//Scale factor
 789			// 2003-06-11 - Nicola Asuni : changed if/else with switch statement
 790			switch (strtolower($unit)){
 791				case 'pt': {$this->k=1; break;}
 792				case 'mm': {$this->k=72/25.4; break;}
 793				case 'cm': {$this->k=72/2.54; break;}
 794				case 'in': {$this->k=72; break;}
 795				default : {$this->Error('Incorrect unit: '.$unit); break;}
 796			}
 797
 798			//Page format
 799			if(is_string($format)) {
 800				// 2002-07-24 - Nicola Asuni (info@tecnick.com)
 801				// Added new page formats (45 standard ISO paper formats and 4 american common formats).
 802				// Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
 803				switch (strtoupper($format)){
 804					case '4A0': {$format = array(4767.87,6740.79); break;}
 805					case '2A0': {$format = array(3370.39,4767.87); break;}
 806					case 'A0': {$format = array(2383.94,3370.39); break;}
 807					case 'A1': {$format = array(1683.78,2383.94); break;}
 808					case 'A2': {$format = array(1190.55,1683.78); break;}
 809					case 'A3': {$format = array(841.89,1190.55); break;}
 810					case 'A4': default: {$format = array(595.28,841.89); break;}
 811					case 'A5': {$format = array(419.53,595.28); break;}
 812					case 'A6': {$format = array(297.64,419.53); break;}
 813					case 'A7': {$format = array(209.76,297.64); break;}
 814					case 'A8': {$format = array(147.40,209.76); break;}
 815					case 'A9': {$format = array(104.88,147.40); break;}
 816					case 'A10': {$format = array(73.70,104.88); break;}
 817					case 'B0': {$format = array(2834.65,4008.19); break;}
 818					case 'B1': {$format = array(2004.09,2834.65); break;}
 819					case 'B2': {$format = array(1417.32,2004.09); break;}
 820					case 'B3': {$format = array(1000.63,1417.32); break;}
 821					case 'B4': {$format = array(708.66,1000.63); break;}
 822					case 'B5': {$format = array(498.90,708.66); break;}
 823					case 'B6': {$format = array(354.33,498.90); break;}
 824					case 'B7': {$format = array(249.45,354.33); break;}
 825					case 'B8': {$format = array(175.75,249.45); break;}
 826					case 'B9': {$format = array(124.72,175.75); break;}
 827					case 'B10': {$format = array(87.87,124.72); break;}
 828					case 'C0': {$format = array(2599.37,3676.54); break;}
 829					case 'C1': {$format = array(1836.85,2599.37); break;}
 830					case 'C2': {$format = array(1298.27,1836.85); break;}
 831					case 'C3': {$format = array(918.43,1298.27); break;}
 832					case 'C4': {$format = array(649.13,918.43); break;}
 833					case 'C5': {$format = array(459.21,649.13); break;}
 834					case 'C6': {$format = array(323.15,459.21); break;}
 835					case 'C7': {$format = array(229.61,323.15); break;}
 836					case 'C8': {$format = array(161.57,229.61); break;}
 837					case 'C9': {$format = array(113.39,161.57); break;}
 838					case 'C10': {$format = array(79.37,113.39); break;}
 839					case 'RA0': {$format = array(2437.80,3458.27); break;}
 840					case 'RA1': {$format = array(1729.13,2437.80); break;}
 841					case 'RA2': {$format = array(1218.90,1729.13); break;}
 842					case 'RA3': {$format = array(864.57,1218.90); break;}
 843					case 'RA4': {$format = array(609.45,864.57); break;}
 844					case 'SRA0': {$format = array(2551.18,3628.35); break;}
 845					case 'SRA1': {$format = array(1814.17,2551.18); break;}
 846					case 'SRA2': {$format = array(1275.59,1814.17); break;}
 847					case 'SRA3': {$format = array(907.09,1275.59); break;}
 848					case 'SRA4': {$format = array(637.80,907.09); break;}
 849					case 'LETTER': {$format = array(612.00,792.00); break;}
 850					case 'LEGAL': {$format = array(612.00,1008.00); break;}
 851					case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
 852					case 'FOLIO': {$format = array(612.00,936.00); break;}
 853					// default: {$this->Error('Unknown page format: '.$format); break;}
 854					// END CHANGES Nicola Asuni
 855				}
 856				$this->fwPt=$format[0];
 857				$this->fhPt=$format[1];
 858			}
 859			else {
 860				$this->fwPt=$format[0]*$this->k;
 861				$this->fhPt=$format[1]*$this->k;
 862			}
 863
 864			$this->fw=$this->fwPt/$this->k;
 865			$this->fh=$this->fhPt/$this->k;
 866
 867			//Page orientation
 868			$orientation=strtolower($orientation);
 869			if($orientation=='p' or $orientation=='portrait') {
 870				$this->DefOrientation='P';
 871				$this->wPt=$this->fwPt;
 872				$this->hPt=$this->fhPt;
 873			}
 874			elseif($orientation=='l' or $orientation=='landscape') {
 875				$this->DefOrientation='L';
 876				$this->wPt=$this->fhPt;
 877				$this->hPt=$this->fwPt;
 878			}
 879			else {
 880				$this->Error('Incorrect orientation: '.$orientation);
 881			}
 882
 883			$this->CurOrientation=$this->DefOrientation;
 884			$this->w=$this->wPt/$this->k;
 885			$this->h=$this->hPt/$this->k;
 886			//Page margins (1 cm)
 887			$margin=28.35/$this->k;
 888			$this->SetMargins($margin,$margin);
 889			//Interior cell margin (1 mm)
 890			$this->cMargin=$margin/10;
 891			//Line width (0.2 mm)
 892			$this->LineWidth=.567/$this->k;
 893			//Automatic page break
 894			$this->SetAutoPageBreak(true,2*$margin);
 895			//Full width display mode
 896			$this->SetDisplayMode('fullwidth');
 897			//Compression
 898			$this->SetCompression(true);
 899			//Set default PDF version number
 900			$this->PDFVersion = "1.3";
 901			
 902			$this->encoding = $encoding;
 903			$this->b = 0;
 904			$this->i = 0;
 905			$this->u = 0;
 906			$this->HREF = '';
 907			$this->fontlist = array("arial", "times", "courier", "helvetica", "symbol");
 908			$this->issetfont = false;
 909			$this->issetcolor = false;
 910			$this->tableborder = 0;
 911			$this->tdbegin = false;
 912			$this->tdwidth=  0;
 913			$this->tdheight = 0;
 914			$this->tdalign = "L";
 915			$this->tdbgcolor = false;
 916			
 917			$this->SetFillColor(200, 200, 200, true);
 918			$this->SetTextColor(0, 0, 0, true);
 919		}
 920
 921		/**
 922		* Set the image scale.
 923		* @param float $scale image scale.
 924		* @author Nicola Asuni
 925		* @since 1.5.2
 926		*/
 927		function setImageScale($scale) {
 928			$this->imgscale=$scale;
 929		}
 930
 931		/**
 932		* Returns the image scale.
 933		* @return float image scale.
 934		* @author Nicola Asuni
 935		* @since 1.5.2
 936		*/
 937		function getImageScale() {
 938			return $this->imgscale;
 939		}
 940
 941		/**
 942		* Returns the page width in units.
 943		* @return int page width.
 944		* @author Nicola Asuni
 945		* @since 1.5.2
 946		*/
 947		function getPageWidth() {
 948			return $this->w;
 949		}
 950
 951		/**
 952		* Returns the page height in units.
 953		* @return int page height.
 954		* @author Nicola Asuni
 955		* @since 1.5.2
 956		*/
 957		function getPageHeight() {
 958			return $this->h;
 959		}
 960
 961		/**
 962		* Returns the page break margin.
 963		* @return int page break margin.
 964		* @author Nicola Asuni
 965		* @since 1.5.2
 966		*/
 967		function getBreakMargin() {
 968			return $this->bMargin;
 969		}
 970
 971		/**
 972		* Returns the scale factor (number of points in user unit).
 973		* @return int scale factor.
 974		* @author Nicola Asuni
 975		* @since 1.5.2
 976		*/
 977		function getScaleFactor() {
 978			return $this->k;
 979		}
 980
 981		/**
 982		* Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
 983		* @param float $left Left margin.
 984		* @param float $top Top margin.
 985		* @param float $right Right margin. Default value is the left one.
 986		* @since 1.0
 987		* @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
 988		*/
 989		function SetMargins($left, $top, $right=-1) {
 990			//Set left, top and right margins
 991			$this->lMargin=$left;
 992			$this->tMargin=$top;
 993			if($right==-1) {
 994				$right=$left;
 995			}
 996			$this->rMargin=$right;
 997		}
 998
 999		/**
1000		* Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
1001		* @param float $margin The margin.
1002		* @since 1.4
1003		* @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
1004		*/
1005		function SetLeftMargin($margin) {
1006			//Set left margin
1007			$this->lMargin=$margin;
1008			if(($this->page>0) and ($this->x<$margin)) {
1009				$this->x=$margin;
1010			}
1011		}
1012
1013		/**
1014		* Defines the top margin. The method can be called before creating the first page.
1015		* @param float $margin The margin.
1016		* @since 1.5
1017		* @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
1018		*/
1019		function SetTopMargin($margin) {
1020			//Set top margin
1021			$this->tMargin=$margin;
1022		}
1023
1024		/**
1025		* Defines the right margin. The method can be called before creating the first page.
1026		* @param float $margin The margin.
1027		* @since 1.5
1028		* @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
1029		*/
1030		function SetRightMargin($margin) {
1031			//Set right margin
1032			$this->rMargin=$margin;
1033		}
1034
1035		/**
1036		* Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
1037		* @param boolean $auto Boolean indicating if mode should be on or off.
1038		* @param float $margin Distance from the bottom of the page.
1039		* @since 1.0
1040		* @see Cell(), MultiCell(), AcceptPageBreak()
1041		*/
1042		function SetAutoPageBreak($auto, $margin=0) {
1043			//Set auto page break mode and triggering margin
1044			$this->AutoPageBreak=$auto;
1045			$this->bMargin=$margin;
1046			$this->PageBreakTrigger=$this->h-$margin;
1047		}
1048
1049		/**
1050		* Defines the way the document is to be displayed by the viewer. The zoom level can be set: pages can be displayed entirely on screen, occupy the full width of the window, use real size, be scaled by a specific zooming factor or use viewer default (configured in the Preferences menu of Acrobat). The page layout can be specified too: single at once, continuous display, two columns or viewer default. By default, documents use the full width mode with continuous display.
1051		* @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
1052		* @param string $layout The page layout. Possible values are:<ul><li>single: displays one page at once</li><li>continuous: displays pages continuously (default)</li><li>two: displays two pages on two columns</li><li>default: uses viewer default mode</li></ul>
1053		* @since 1.2
1054		*/
1055		function SetDisplayMode($zoom, $layout='continuous') {
1056			//Set display mode in viewer
1057			if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
1058				$this->ZoomMode=$zoom;
1059			}
1060			else {
1061				$this->Error('Incorrect zoom display mode: '.$zoom);
1062			}
1063			if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') {
1064				$this->LayoutMode=$layout;
1065			}
1066			else {
1067				$this->Error('Incorrect layout display mode: '.$layout);
1068			}
1069		}
1070
1071		/**
1072		* Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
1073		* Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
1074		* @param boolean $compress Boolean indicating if compression must be enabled.
1075		* @since 1.4
1076		*/
1077		function SetCompression($compress) {
1078			//Set page compression
1079			if(function_exists('gzcompress')) {
1080				$this->compress=$compress;
1081			}
1082			else {
1083				$this->compress=false;
1084			}
1085		}
1086
1087		/**
1088		* Defines the title of the document.
1089		* @param string $title The title.
1090		* @since 1.2
1091		* @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
1092		*/
1093		function SetTitle($title) {
1094			//Title of document
1095			$this->title=$title;
1096		}
1097
1098		/**
1099		* Defines the subject of the document.
1100		* @param string $subject The subject.
1101		* @since 1.2
1102		* @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
1103		*/
1104		function SetSubject($subject) {
1105			//Subject of document
1106			$this->subject=$subject;
1107		}
1108
1109		/**
1110		* Defines the author of the document.
1111		* @param string $author The name of the author.
1112		* @since 1.2
1113		* @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
1114		*/
1115		function SetAuthor($author) {
1116			//Author of document
1117			$this->author=$author;
1118		}
1119
1120		/**
1121		* Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
1122		* @param string $keywords The list of keywords.
1123		* @since 1.2
1124		* @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
1125		*/
1126		function SetKeywords($keywords) {
1127			//Keywords of document
1128			$this->keywords=$keywords;
1129		}
1130
1131		/**
1132		* Defines the creator of the document. This is typically the name of the application that generates the PDF.
1133		* @param string $creator The name of the creator.
1134		* @since 1.2
1135		* @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
1136		*/
1137		function SetCreator($creator) {
1138			//Creator of document
1139			$this->creator=$creator;
1140		}
1141
1142		/**
1143		* Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
1144		* <b>Example:</b><br />
1145		* <pre>
1146		* class PDF extends TCPDF {
1147		* 	function Footer() {
1148		* 		//Go to 1.5 cm from bottom
1149		* 		$this->SetY(-15);
1150		* 		//Select Arial italic 8
1151		* 		$this->SetFont('Arial','I',8);
1152		* 		//Print current and total page numbers
1153		* 		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
1154		* 	}
1155		* }
1156		* $pdf=new PDF();
1157		* $pdf->AliasNbPages();
1158		* </pre>
1159		* @param string $alias The alias. Default value: {nb}.
1160		* @since 1.4
1161		* @see PageNo(), Footer()
1162		*/
1163		function AliasNbPages($alias='{nb}') {
1164			//Define an alias for total number of pages
1165			$this->AliasNbPages = $this->_escapetext($alias);
1166		}
1167
1168		/**
1169		* This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
1170		* 2004-06-11 :: Nicola Asuni : changed bold tag with strong
1171		* @param string $msg The error message
1172		* @since 1.0
1173		*/
1174		function Error($msg) {
1175			//Fatal error
1176			die('<strong>TCPDF error: </strong>'.$msg);
1177		}
1178
1179		/**
1180		* This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
1181		* Note: no page is created by this method
1182		* @since 1.0
1183		* @see AddPage(), Close()
1184		*/
1185		function Open() {
1186			//Begin document
1187			$this->state=1;
1188		}
1189
1190		/**
1191		* Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document.
1192		* @since 1.0
1193		* @see Open(), Output()
1194		*/
1195		function Close() {
1196			//Terminate document
1197			if($this->state==3) {
1198				return;
1199			}
1200			if($this->page==0) {
1201				$this->AddPage();
1202			}
1203			//Page footer
1204			$this->InFooter=true;
1205			$this->Footer();
1206			$this->InFooter=false;
1207			//Close page
1208			$this->_endpage();
1209			//Close document
1210			$this->_enddoc();
1211		}
1212
1213		/**
1214		* Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer. Then the page is added, the current position set to the top-left corner according to the left and top margins, and Header() is called to display the header.
1215		* The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width.
1216		* The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
1217		* @param string $orientation Page orientation. Possible values are (case insensitive):<ul><li>P or Portrait</li><li>L or Landscape</li></ul> The default value is the one passed to the constructor.
1218		* @since 1.0
1219		* @see TCPDF(), Header(), Footer(), SetMargins()
1220		*/
1221		function AddPage($orientation='') {
1222			//Start a new page
1223			if($this->state==0) {
1224				$this->Open();
1225			}
1226			$family=$this->FontFamily;
1227			$style=$this->FontStyle.($this->underline ? 'U' : '');
1228			$size=$this->FontSizePt;
1229			$lw=$this->LineWidth;
1230			$dc=$this->DrawColor;
1231			$fc=$this->FillColor;
1232			$tc=$this->TextColor;
1233			$cf=$this->ColorFlag;
1234			if($this->page>0) {
1235				//Page footer
1236				$this->InFooter=true;
1237				$this->Footer();
1238				$this->InFooter=false;
1239				//Close page
1240				$this->_endpage();
1241			}
1242			//Start new page
1243			$this->_beginpage($orientation);
1244			//Set line cap style to square
1245			$this->_out('2 J');
1246			//Set line width
1247			$this->LineWidth=$lw;
1248			$this->_out(sprintf('%.2f w',$lw*$this->k));
1249			//Set font
1250			if($family) {
1251				$this->SetFont($family,$style,$size);
1252			}
1253			//Set colors
1254			$this->DrawColor=$dc;
1255			if($dc!='0 G') {
1256				$this->_out($dc);
1257			}
1258			$this->FillColor=$fc;
1259			if($fc!='0 g') {
1260				$this->_out($fc);
1261			}
1262			$this->TextColor=$tc;
1263			$this->ColorFlag=$cf;
1264			//Page header
1265			$this->Header();
1266			//Restore line width
1267			if($this->LineWidth!=$lw) {
1268				$this->LineWidth=$lw;
1269				$this->_out(sprintf('%.2f w',$lw*$this->k));
1270			}
1271			//Restore font
1272			if($family) {
1273				$this->SetFont($family,$style,$size);
1274			}
1275			//Restore colors
1276			if($this->DrawColor!=$dc) {
1277				$this->DrawColor=$dc;
1278				$this->_out($dc);
1279			}
1280			if($this->FillColor!=$fc) {
1281				$this->FillColor=$fc;
1282				$this->_out($fc);
1283			}
1284			$this->TextColor=$tc;
1285			$this->ColorFlag=$cf;
1286		}
1287		
1288		
1289		
1290		/**
1291	 	 * Set header data.
1292		 * @param string $ln header image logo
1293		 * @param string $lw header image logo width in mm
1294		 * @param string $ht string to print as title on document header
1295		 * @param string $hs string to print on document header
1296		*/
1297		function setHeaderData($ln="", $lw=0, $ht="", $hs="") {
1298			$this->header_logo = $ln;
1299			$this->header_logo_width = $lw;
1300			$this->header_title = $ht;
1301			$this->header_string = $hs;
1302		}
1303		
1304		/**
1305	 	 * Set header margin.
1306		 * (minimum distance between header and top page margin)
1307		 * @param int $hm distance in millimeters
1308		*/
1309		function setHeaderMargin($hm=10) {
1310			$this->header_margin = $hm;
1311		}
1312		
1313		/**
1314	 	 * Set footer margin.
1315		 * (minimum distance between footer and bottom page margin)
1316		 * @param int $fm distance in millimeters
1317		*/
1318		function setFooterMargin($fm=10) {
1319			$this->footer_margin = $fm;
1320		}
1321		
1322		/**
1323	 	 * This method is used to render the page header.
1324	 	 * It is automatically called by AddPage() and could be overwritten in your own inherited class.
1325		 */
1326		function Header() {
1327			if ($this->print_header) {
1328				
1329				if (!isset($this->original_lMargin)) {
1330					$this->original_lMargin = $this->lMargin;
1331				}
1332				if (!isset($this->original_rMargin)) {
1333					$this->original_rMargin = $this->rMargin;
1334				}
1335				
1336				//set current position
1337				$this->SetXY($this->original_lMargin, $this->header_margin);
1338				
1339				if (($this->header_logo) AND ($this->header_logo != K_BLANK_IMAGE)) {
1340					$this->Image(K_PATH_IMAGES.$this->header_logo, $this->original_lMargin, $this->header_margin, $this->header_logo_width);
1341				}
1342				else {
1343					$this->img_rb_y = $this->GetY();
1344				}
1345				
1346				$cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2);
1347				
1348				$header_x = $this->original_lMargin + ($this->header_logo_width * 1.05); //set left margin for text data cell
1349				
1350				// header title
1351				$this->SetFont($this->header_font[0], 'B', $this->header_font[2] + 1);
1352				$this->SetX($header_x);
1353				$this->Cell($this->header_width, $cell_height, $this->header_title, 0, 1, 'L'); 
1354				
1355				// header string
1356				$this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
1357				$this->SetX($header_x);
1358				$this->MultiCell($this->header_width, $cell_height, $this->header_string, 0, 'L', 0);
1359				
1360				// print an ending header line
1361				if (empty($this->header_width)) {
1362					//set style for cell border
1363					$this->SetLineWidth(0.3);
1364					$this->SetDrawColor(0, 0, 0);
1365					$this->SetY(1 + max($this->img_rb_y, $this->GetY()));
1366					$this->SetX($this->original_lMargin);
1367					$this->Cell(0, 0, '', 'T', 0, 'C'); 
1368				}
1369				
1370				//restore position
1371				$this->SetXY($this->original_lMargin, $this->tMargin);
1372			}
1373		}
1374		
1375		/**
1376	 	 * This method is used to render the page footer. 
1377	 	 * It is automatically called by AddPage() and could be overwritten in your own inherited class.
1378		 */
1379		function Footer() {
1380			if ($this->print_footer) {
1381				
1382				if (!isset($this->original_lMargin)) {
1383					$this->original_lMargin = $this->lMargin;
1384				}
1385				if (!isset($this->original_rMargin)) {
1386					$this->original_rMargin = $this->rMargin;
1387				}
1388				
1389				//set font
1390				$this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]);
1391				//set style for cell border
1392				$line_width = 0.3;
1393				$this->SetLineWidth($line_width);
1394				$this->SetDrawColor(0, 0, 0);
1395				
1396				$footer_height = round((K_CELL_HEIGHT_RATIO * $this->footer_font[2]) / $this->k, 2); //footer height
1397				//get footer y position
1398				$footer_y = $this->h - $this->footer_margin - $footer_height;
1399				//set current position
1400				$this->SetXY($this->original_lMargin, $footer_y); 
1401				
1402				//print document barcode
1403				if ($this->barcode) {
1404					$this->Ln();
1405					$barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin)); //max width
1406					$this->writeBarcode($this->original_lMargin, $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode);
1407				}
1408				
1409				$this->SetXY($this->original_lMargin, $footer_y); 
1410				
1411				//Print page number
1412				$this->Cell(0, $footer_height, $this->l['w_page']." ".$this->PageNo().' / {nb}', 'T', 0, 'R'); 
1413			}
1414		}
1415		
1416		/**
1417		* Returns the current page number.
1418		* @return int page number
1419		* @since 1.0
1420		* @see AliasNbPages()
1421		*/
1422		function PageNo() {
1423			//Get current page number
1424			return $this->page;
1425		}
1426
1427		/**
1428		* Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
1429		* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1430		* @param int $g Green component (between 0 and 255)
1431		* @param int $b Blue component (between 0 and 255)
1432		* @since 1.3
1433		* @see SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
1434		*/
1435		function SetDrawColor($r, $g=-1, $b=-1) {
1436			//Set color for all stroking operations
1437			if(($r==0 and $g==0 and $b==0) or $g==-1) {
1438				$this->DrawColor=sprintf('%.3f G',$r/255);
1439			}
1440			else {
1441				$this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
1442			}
1443			if($this->page>0) {
1444				$this->_out($this->DrawColor);
1445			}
1446		}
1447
1448		/**
1449		* Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
1450		* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1451		* @param int $g Green component (between 0 and 255)
1452		* @param int $b Blue component (between 0 and 255)
1453		* @param boolean $storeprev if true stores the RGB array on $prevFillColor variable.
1454		* @since 1.3
1455		* @see SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
1456		*/
1457		function SetFillColor($r, $g=-1, $b=-1, $storeprev=false) {
1458			//Set color for all filling operations
1459			if(($r==0 and $g==0 and $b==0) or $g==-1) {
1460				$this->FillColor=sprintf('%.3f g',$r/255);
1461			}
1462			else {
1463				$this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
1464			}
1465			$this->ColorFlag=($this->FillColor!=$this->TextColor);
1466			if($this->page>0) {
1467				$this->_out($this->FillColor);
1468			}
1469			if ($storeprev) {
1470				// store color as previous value
1471				$this->prevFillColor = array($r, $g, $b);
1472			}
1473		}
1474
1475		/**
1476		* Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
1477		* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1478		* @param int $g Green component (between 0 and 255)
1479		* @param int $b Blue component (between 0 and 255)
1480		* @param boolean $storeprev if true stores the RGB array on $prevTextColor variable.
1481		* @since 1.3
1482		* @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
1483		*/
1484		function SetTextColor($r, $g=-1, $b=-1, $storeprev=false) {
1485			//Set color for text
1486			if(($r==0 and $g==0 and $b==0) or $g==-1) {
1487				$this->TextColor=sprintf('%.3f g',$r/255);
1488			}
1489			else {
1490				$this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
1491			}
1492			$this->ColorFlag=($this->FillColor!=$this->TextColor);
1493			if ($storeprev) {
1494				// store color as previous value
1495				$this->prevTextColor = array($r, $g, $b);
1496			}
1497		}
1498
1499		/**
1500		* Returns the length of a string in user unit. A font must be selected.<br>
1501		* Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]
1502		* @param string $s The string whose length is to be computed
1503		* @return int
1504		* @since 1.2
1505		*/
1506		function GetStringWidth($s) {
1507			//Get width of a string in the current font
1508			$s = (string)$s;
1509			$cw = &$this->CurrentFont['cw'];
1510			$w = 0;
1511			if($this->isunicode) {
1512				$unicode = $this->UTF8StringToArray($s);
1513				foreach($unicode as $char) {
1514					if (isset($cw[$char])) {
1515						$w+=$cw[$char];
1516					} elseif(isset($cw[ord($char)])) {
1517						$w+=$cw[ord($char)];
1518					} elseif(isset($cw[chr($char)])) {
1519						$w+=$cw[chr($char)];
1520					} elseif(isset($this->CurrentFont['desc']['MissingWidth'])) {
1521						$w += $this->CurrentFont['desc']['MissingWidth']; // set default size
1522					} else {
1523						$w += 500;
1524					}
1525				}
1526			} else {
1527				$l = strlen($s);
1528				for($i=0; $i<$l; $i++) {
1529					if (isset($cw[$s{$i}])) {
1530						$w += $cw[$s{$i}];
1531					} else if (isset($cw[ord($s{$i})])) {
1532						$w += $cw[ord($s{$i})];
1533					}
1534				}
1535			}
1536			return ($w * $this->FontSize / 1000);
1537		}
1538
1539		/**
1540		* Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
1541		* @param float $width The width.
1542		* @since 1.0
1543		* @see Line(), Rect(), Cell(), MultiCell()
1544		*/
1545		function SetLineWidth($width) {
1546			//Set line width
1547			$this->LineWidth=$width;
1548			if($this->page>0) {
1549				$this->_out(sprintf('%.2f w',$width*$this->k));
1550			}
1551		}
1552
1553		/**
1554		* Draws a line between two points.
1555		* @param float $x1 Abscissa of first point
1556		* @param float $y1 Ordinate of first point
1557		* @param float $x2 Abscissa of second point
1558		* @param float $y2 Ordinate of second point
1559		* @since 1.0
1560		* @see SetLineWidth(), SetDrawColor()
1561		*/
1562		function Line($x1, $y1, $x2, $y2) {
1563			//Draw a line
1564			$this->_out(sprintf('%.2f %.2f m %.2f %.2f l S', $x1*$this->k, ($this->h-$y1)*$this->k, $x2*$this->k, ($this->h-$y2)*$this->k));
1565		}
1566
1567		/**
1568		* Outputs a rectangle. It can be drawn (border only), filled (with no border) or both.
1569		* @param float $x Abscissa of upper-left corner
1570		* @param float $y Ordinate of upper-left corner
1571		* @param float $w Width
1572		* @param float $h Height
1573		* @param string $style Style of rendering. Possible values are:<ul><li>D or empty string: draw (default)</li><li>F: fill</li><li>DF or FD: draw and fill</li></ul>
1574		* @since 1.0
1575		* @see SetLineWidth(), SetDrawColor(), SetFillColor()
1576		*/
1577		function Rect($x, $y, $w, $h, $style='') {
1578			//Draw a rectangle
1579			if($style=='F') {
1580				$op='f';
1581			}
1582			elseif($style=='FD' or $style=='DF') {
1583				$op='B';
1584			}
1585			else {
1586				$op='S';
1587			}
1588			$this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
1589		}
1590
1591		/**
1592		* 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.
1593		* Support UTF-8 Unicode [Nicola Asuni, 2005-01-02].
1594		* <b>Example</b>:<br />
1595		* <pre>
1596		* $pdf->AddFont('Comic','I');
1597		* // is equivalent to:
1598		* $pdf->AddFont('Comic','I','comici.php');
1599		* </pre>
1600		* @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
1601		* @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
1602		* @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no space.
1603		* @since 1.5
1604		* @see SetFont()
1605		*/
1606		function AddFont($family, $style='', $file='') {
1607			if(empty($family)) {
1608				return;
1609			}
1610
1611			//Add a TrueType or Type1 font
1612			$family = strtolower($family);
1613			if((!$this->isunicode) AND ($family == 'arial')) {
1614				$family = 'helvetica';
1615			}
1616
1617			$style=strtoupper($style);
1618			$style=str_replace('U','',$style);
1619			if($style == 'IB') {
1620				$style = 'BI';
1621			}
1622
1623			$fontkey = $family.$style;
1624			// check if the font has been already added
1625			if(isset($this->fonts[$fontkey])) {
1626				return;
1627			}
1628
1629			if($file=='') {
1630				$file = str_replace(' ', '', $family).strtolower($style).'.php';
1631			}
1632			if(!file_exists($this->_getfontpath().$file)) {
1633				// try to load the basic file without styles
1634				$file = str_replace(' ', '', $family).'.php';
1635			}
1636
1637			include($this->_getfontpath().$file);
1638
1639			if(!isset($name) AND !isset($fpdf_charwidths)) {
1640				$this->Error('Could not include font definition file');
1641			}
1642
1643			$i = count($this->fonts)+1;
1644
1645			if($this->isunicode) {
1646				$this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg);
1647				$fpdf_charwidths[$fontkey] = $cw;
1648			} else {
1649				$this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]);
1650			}
1651
1652			if(isset($diff) AND (!empty($diff))) {
1653				//Search existing encodings
1654				$d=0;
1655				$nb=count($this->diffs);
1656				for($i=1;$i<=$nb;$i++) {
1657					if($this->diffs[$i]==$diff) {
1658						$d=$i;
1659						break;
1660					}
1661				}
1662				if($d==0) {
1663					$d=$nb+1;
1664					$this->diffs[$d]=$diff;
1665				}
1666				$this->fonts[$fontkey]['diff']=$d;
1667			}
1668			if(!empty($file)) {
1669				if((strcasecmp($type,"TrueType") == 0) OR (strcasecmp($type,"TrueTypeUnicode") == 0)) {
1670					$this->FontFiles[$file]=array('length1'=>$originalsize);
1671				}
1672				else {
1673					$this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
1674				}
1675			}
1676		}
1677
1678		/**
1679		* Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid.
1680		* The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
1681		* The method can be called before the first page is created and the font is retained from page to page.
1682		If you just wish to change the current font size, it is simpler to call SetFontSize().
1683		* Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the FPDF_FONTPATH constant</li></ul><br />
1684		* Example for the last case (note the trailing slash):<br />
1685		* <pre>
1686		* define('FPDF_FONTPATH','/home/www/font/');
1687		* require('tcpdf.php');
1688		*
1689		* //Times regular 12
1690		* $pdf->SetFont('Times');
1691		* //Arial bold 14
1692		* $pdf->SetFont('Arial','B',14);
1693		* //Removes bold
1694		* $pdf->SetFont('');
1695		* //Times bold, italic and underlined 14
1696		* $pdf->SetFont('Times','BIU');
1697		* </pre><br />
1698		* If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated.
1699		* @param string $family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained.
1700		* @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li></ul>or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats
1701		* @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the documeā€¦

Large files files are truncated, but you can click here to view the full file