/lib/tcpdf/tcpdf.php
PHP | 4137 lines | 2321 code | 305 blank | 1511 comment | 373 complexity | 4e978c04afa0fd8cfe9fc5ed9a91e829 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- //============================================================+
- // File name : tcpdf.php
- // Begin : 2002-08-03
- // Last Update : 2006-08-05
- // Author : Nicola Asuni
- // Version : 1.53.0.TC023_PHP4
- // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
- //
- // Description : This is a PHP4 class for generating PDF files
- // on-the-fly without requiring external
- // extensions.
- //
- // IMPORTANT:
- // This class is an extension and improvement of the public Domain
- // FPDF class by Olivier Plathey (http://www.fpdf.org).
- //
- // Main changes by Nicola Asuni:
- // PHP4 porting;
- // UTF-8 Unicode support;
- // code refactoring;
- // source code clean up;
- // code style and formatting;
- // source code documentation using phpDocumentor (www.phpdoc.org);
- // All ISO page formats were included;
- // image scale factor;
- // 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;
- // 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/);
- // defines standard Header() and Footer() methods.
- //============================================================+
-
- /**
- * include configuration file
- */
- require_once(dirname(__FILE__).'/config/tcpdf_config.php');
-
-
- /**
- * TCPDF Class.
- * @package com.tecnick.tcpdf
- */
-
- /**
- * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
- * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
- * <h3>TCPDF main changes from FPDF are:</h3><ul>
- * <li>PHP4 porting</li>
- * <li>UTF-8 Unicode support</li>
- * <li>source code clean up</li>
- * <li>code style and formatting</li>
- * <li>source code documentation using phpDocumentor (www.phpdoc.org)</li>
- * <li>All ISO page formats were included</li>
- * <li>image scale factor</li>
- * <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>
- * <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>
- * <li>defines standard Header() and Footer() methods.</li>
- * </ul>
- * Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p>
- * @name TCPDF
- * @package com.tecnick.tcpdf
- * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
- * @author Nicola Asuni
- * @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
- * @link http://tcpdf.sourceforge.net
- * @license http://www.gnu.org/copyleft/lesser.html LGPL
- @version 1.53.0.TC023_PHP4
- */
-
- if(!class_exists('TCPDF')) {
- /**
- * define default PDF document producer
- */
- define('PDF_PRODUCER','TCPDF 1.53.0.TC023_PHP4 (http://tcpdf.sourceforge.net)');
-
- /**
- * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
- * This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
- * 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>
- * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
- * To add your own TTF fonts please read /fonts/README.TXT
- * @name TCPDF
- * @package com.tecnick.tcpdf
- * @version 1.53.0.TC023
- * @author Nicola Asuni
- * @link http://tcpdf.sourceforge.net
- * @license http://www.gnu.org/copyleft/lesser.html LGPL
- */
- class TCPDF {
- //var properties
-
- /**
- * @var current page number
- * @access protected
- */
- var $page;
-
- /**
- * @var current object number
- * @access protected
- */
- var $n;
-
- /**
- * @var array of object offsets
- * @access protected
- */
- var $offsets;
-
- /**
- * @var buffer holding in-memory PDF
- * @access protected
- */
- var $buffer;
-
- /**
- * @var array containing pages
- * @access protected
- */
- var $pages;
-
- /**
- * @var current document state
- * @access protected
- */
- var $state;
-
- /**
- * @var compression flag
- * @access protected
- */
- var $compress;
-
- /**
- * @var default orientation
- * @access protected
- */
- var $DefOrientation;
-
- /**
- * @var current orientation
- * @access protected
- */
- var $CurOrientation;
-
- /**
- * @var array indicating orientation changes
- * @access protected
- */
- var $OrientationChanges;
-
- /**
- * @var scale factor (number of points in user unit)
- * @access protected
- */
- var $k;
-
- /**
- * @var width of page format in points
- * @access protected
- */
- var $fwPt;
-
- /**
- * @var height of page format in points
- * @access protected
- */
- var $fhPt;
-
- /**
- * @var width of page format in user unit
- * @access protected
- */
- var $fw;
-
- /**
- * @var height of page format in user unit
- * @access protected
- */
- var $fh;
-
- /**
- * @var current width of page in points
- * @access protected
- */
- var $wPt;
-
- /**
- * @var current height of page in points
- * @access protected
- */
- var $hPt;
-
- /**
- * @var current width of page in user unit
- * @access protected
- */
- var $w;
-
- /**
- * @var current height of page in user unit
- * @access protected
- */
- var $h;
-
- /**
- * @var left margin
- * @access protected
- */
- var $lMargin;
-
- /**
- * @var top margin
- * @access protected
- */
- var $tMargin;
-
- /**
- * @var right margin
- * @access protected
- */
- var $rMargin;
-
- /**
- * @var page break margin
- * @access protected
- */
- var $bMargin;
-
- /**
- * @var cell margin
- * @access protected
- */
- var $cMargin;
-
- /**
- * @var current horizontal position in user unit for cell positioning
- * @access protected
- */
- var $x;
-
- /**
- * @var current vertical position in user unit for cell positioning
- * @access protected
- */
- var $y;
-
- /**
- * @var height of last cell printed
- * @access protected
- */
- var $lasth;
-
- /**
- * @var line width in user unit
- * @access protected
- */
- var $LineWidth;
-
- /**
- * @var array of standard font names
- * @access protected
- */
- var $CoreFonts;
-
- /**
- * @var array of used fonts
- * @access protected
- */
- var $fonts;
-
- /**
- * @var array of font files
- * @access protected
- */
- var $FontFiles;
-
- /**
- * @var array of encoding differences
- * @access protected
- */
- var $diffs;
-
- /**
- * @var array of used images
- * @access protected
- */
- var $images;
-
- /**
- * @var array of links in pages
- * @access protected
- */
- var $PageLinks;
-
- /**
- * @var array of internal links
- * @access protected
- */
- var $links;
-
- /**
- * @var current font family
- * @access protected
- */
- var $FontFamily;
-
- /**
- * @var current font style
- * @access protected
- */
- var $FontStyle;
-
- /**
- * @var underlining flag
- * @access protected
- */
- var $underline;
-
- /**
- * @var current font info
- * @access protected
- */
- var $CurrentFont;
-
- /**
- * @var current font size in points
- * @access protected
- */
- var $FontSizePt;
-
- /**
- * @var current font size in user unit
- * @access protected
- */
- var $FontSize;
-
- /**
- * @var commands for drawing color
- * @access protected
- */
- var $DrawColor;
-
- /**
- * @var commands for filling color
- * @access protected
- */
- var $FillColor;
-
- /**
- * @var commands for text color
- * @access protected
- */
- var $TextColor;
-
- /**
- * @var indicates whether fill and text colors are different
- * @access protected
- */
- var $ColorFlag;
-
- /**
- * @var word spacing
- * @access protected
- */
- var $ws;
-
- /**
- * @var automatic page breaking
- * @access protected
- */
- var $AutoPageBreak;
-
- /**
- * @var threshold used to trigger page breaks
- * @access protected
- */
- var $PageBreakTrigger;
-
- /**
- * @var flag set when processing footer
- * @access protected
- */
- var $InFooter;
-
- /**
- * @var zoom display mode
- * @access protected
- */
- var $ZoomMode;
-
- /**
- * @var layout display mode
- * @access protected
- */
- var $LayoutMode;
-
- /**
- * @var title
- * @access protected
- */
- var $title;
-
- /**
- * @var subject
- * @access protected
- */
- var $subject;
-
- /**
- * @var author
- * @access protected
- */
- var $author;
-
- /**
- * @var keywords
- * @access protected
- */
- var $keywords;
-
- /**
- * @var creator
- * @access protected
- */
- var $creator;
-
- /**
- * @var alias for total number of pages
- * @access protected
- */
- var $AliasNbPages;
-
- /**
- * @var right-bottom corner X coordinate of inserted image
- * @since 2002-07-31
- * @author Nicola Asuni
- * @access protected
- */
- var $img_rb_x;
-
- /**
- * @var right-bottom corner Y coordinate of inserted image
- * @since 2002-07-31
- * @author Nicola Asuni
- * @access protected
- */
- var $img_rb_y;
-
- /**
- * @var image scale factor
- * @since 2004-06-14
- * @author Nicola Asuni
- * @access protected
- */
- var $imgscale = 1;
-
- /**
- * @var boolean set to true when the input text is unicode (require unicode fonts)
- * @since 2005-01-02
- * @author Nicola Asuni
- * @access protected
- */
- var $isunicode = false;
-
- /**
- * @var PDF version
- * @since 1.5.3
- * @access protected
- */
- var $PDFVersion = "1.3";
-
-
- // ----------------------
-
- /**
- * @var Minimum distance between header and top page margin.
- * @access private
- */
- var $header_margin;
-
- /**
- * @var Minimum distance between footer and bottom page margin.
- * @access private
- */
- var $footer_margin;
-
- /**
- * @var original left margin value
- * @access private
- * @since 1.53.0.TC013
- */
- var $original_lMargin;
-
- /**
- * @var original right margin value
- * @access private
- * @since 1.53.0.TC013
- */
- var $original_rMargin;
-
- /**
- * @var Header font.
- * @access private
- */
- var $header_font;
-
- /**
- * @var Footer font.
- * @access private
- */
- var $footer_font;
-
- /**
- * @var Language templates.
- * @access private
- */
- var $l;
-
- /**
- * @var Barcode to print on page footer (only if set).
- * @access private
- */
- var $barcode = false;
-
- /**
- * @var If true prints header
- * @access private
- */
- var $print_header = true;
-
- /**
- * @var If true prints footer.
- * @access private
- */
- var $print_footer = true;
-
- /**
- * @var Header width (0 = full page width).
- * @access private
- */
- var $header_width = 0;
-
- /**
- * @var Header image logo.
- * @access private
- */
- var $header_logo = "";
-
- /**
- * @var Header image logo width in mm.
- * @access private
- */
- var $header_logo_width = 30;
-
- /**
- * @var String to print as title on document header.
- * @access private
- */
- var $header_title = "";
-
- /**
- * @var String to print on document header.
- * @access private
- */
- var $header_string = "";
-
- /**
- * @var Default number of columns for html table.
- * @access private
- */
- var $default_table_columns = 4;
-
-
- // variables for html parser
-
- /**
- * @var HTML PARSER: store current link.
- * @access private
- */
- var $HREF;
-
- /**
- * @var HTML PARSER: store font list.
- * @access private
- */
- var $fontList;
-
- /**
- * @var HTML PARSER: true when font attribute is set.
- * @access private
- */
- var $issetfont;
-
- /**
- * @var HTML PARSER: true when color attribute is set.
- * @access private
- */
- var $issetcolor;
-
- /**
- * @var HTML PARSER: true in case of ordered list (OL), false otherwise.
- * @access private
- */
- var $listordered = false;
-
- /**
- * @var HTML PARSER: count list items.
- * @access private
- */
- var $listcount = 0;
-
- /**
- * @var HTML PARSER: size of table border.
- * @access private
- */
- var $tableborder = 0;
-
- /**
- * @var HTML PARSER: true at the beginning of table.
- * @access private
- */
- var $tdbegin = false;
-
- /**
- * @var HTML PARSER: table width.
- * @access private
- */
- var $tdwidth = 0;
-
- /**
- * @var HTML PARSER: table height.
- * @access private
- */
- var $tdheight = 0;
-
- /**
- * @var HTML PARSER: table align.
- * @access private
- */
- var $tdalign = "L";
-
- /**
- * @var HTML PARSER: table background color.
- * @access private
- */
- var $tdbgcolor = false;
-
- /**
- * @var Store temporary font size in points.
- * @access private
- */
- var $tempfontsize = 10;
-
- /**
- * @var Bold font style status.
- * @access private
- */
- var $b;
-
- /**
- * @var Underlined font style status.
- * @access private
- */
- var $u;
-
- /**
- * @var Italic font style status.
- * @access private
- */
- var $i;
-
- /**
- * @var spacer for LI tags.
- * @access private
- */
- var $lispacer = "";
-
- /**
- * @var default encoding
- * @access private
- * @since 1.53.0.TC010
- */
- var $encoding = "UTF-8";
-
- /**
- * @var PHP internal encoding
- * @access private
- * @since 1.53.0.TC016
- */
- var $internal_encoding;
-
- /**
- * @var store previous fill color as RGB array
- * @access private
- * @since 1.53.0.TC017
- */
- var $prevFillColor = array(255,255,255);
-
- /**
- * @var store previous text color as RGB array
- * @access private
- * @since 1.53.0.TC017
- */
- var $prevTextColor = array(0,0,0);
-
- /**
- * @var store previous font family
- * @access private
- * @since 1.53.0.TC017
- */
- var $prevFontFamily;
-
- /**
- * @var store previous font style
- * @access private
- * @since 1.53.0.TC017
- */
- var $prevFontStyle;
-
- //------------------------------------------------------------
- // var methods
- //------------------------------------------------------------
-
- /**
- * 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
- * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
- * @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.
- * @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>
- * @param boolean $unicode TRUE means that the input text is unicode (default = true)
- * @param String $encoding charset encoding; default is UTF-8
- */
- function TCPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding="UTF-8") {
-
- /* Set internal character encoding to ASCII */
- if (function_exists("mb_internal_encoding") AND mb_internal_encoding()) {
- $this->internal_encoding = mb_internal_encoding();
- mb_internal_encoding("ASCII");
- }
-
- //Some checks
- $this->_dochecks();
- //Initialization of properties
- $this->isunicode=$unicode;
- $this->page=0;
- $this->n=2;
- $this->buffer='';
- $this->pages=array();
- $this->OrientationChanges=array();
- $this->state=0;
- $this->fonts=array();
- $this->FontFiles=array();
- $this->diffs=array();
- $this->images=array();
- $this->links=array();
- $this->InFooter=false;
- $this->lasth=0;
- $this->FontFamily='';
- $this->FontStyle='';
- $this->FontSizePt=12;
- $this->underline=false;
- $this->DrawColor='0 G';
- $this->FillColor='0 g';
- $this->TextColor='0 g';
- $this->ColorFlag=false;
- $this->ws=0;
- //Standard Unicode fonts
- $this->CoreFonts=array(
- 'courier'=>'Courier',
- 'courierB'=>'Courier-Bold',
- 'courierI'=>'Courier-Oblique',
- 'courierBI'=>'Courier-BoldOblique',
- 'helvetica'=>'Helvetica',
- 'helveticaB'=>'Helvetica-Bold',
- 'helveticaI'=>'Helvetica-Oblique',
- 'helveticaBI'=>'Helvetica-BoldOblique',
- 'times'=>'Times-Roman',
- 'timesB'=>'Times-Bold',
- 'timesI'=>'Times-Italic',
- 'timesBI'=>'Times-BoldItalic',
- 'symbol'=>'Symbol',
- 'zapfdingbats'=>'ZapfDingbats'
- );
-
- //Scale factor
- // 2003-06-11 - Nicola Asuni : changed if/else with switch statement
- switch (strtolower($unit)){
- case 'pt': {$this->k=1; break;}
- case 'mm': {$this->k=72/25.4; break;}
- case 'cm': {$this->k=72/2.54; break;}
- case 'in': {$this->k=72; break;}
- default : {$this->Error('Incorrect unit: '.$unit); break;}
- }
-
- //Page format
- if(is_string($format)) {
- // 2002-07-24 - Nicola Asuni (info@tecnick.com)
- // Added new page formats (45 standard ISO paper formats and 4 american common formats).
- // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
- switch (strtoupper($format)){
- case '4A0': {$format = array(4767.87,6740.79); break;}
- case '2A0': {$format = array(3370.39,4767.87); break;}
- case 'A0': {$format = array(2383.94,3370.39); break;}
- case 'A1': {$format = array(1683.78,2383.94); break;}
- case 'A2': {$format = array(1190.55,1683.78); break;}
- case 'A3': {$format = array(841.89,1190.55); break;}
- case 'A4': default: {$format = array(595.28,841.89); break;}
- case 'A5': {$format = array(419.53,595.28); break;}
- case 'A6': {$format = array(297.64,419.53); break;}
- case 'A7': {$format = array(209.76,297.64); break;}
- case 'A8': {$format = array(147.40,209.76); break;}
- case 'A9': {$format = array(104.88,147.40); break;}
- case 'A10': {$format = array(73.70,104.88); break;}
- case 'B0': {$format = array(2834.65,4008.19); break;}
- case 'B1': {$format = array(2004.09,2834.65); break;}
- case 'B2': {$format = array(1417.32,2004.09); break;}
- case 'B3': {$format = array(1000.63,1417.32); break;}
- case 'B4': {$format = array(708.66,1000.63); break;}
- case 'B5': {$format = array(498.90,708.66); break;}
- case 'B6': {$format = array(354.33,498.90); break;}
- case 'B7': {$format = array(249.45,354.33); break;}
- case 'B8': {$format = array(175.75,249.45); break;}
- case 'B9': {$format = array(124.72,175.75); break;}
- case 'B10': {$format = array(87.87,124.72); break;}
- case 'C0': {$format = array(2599.37,3676.54); break;}
- case 'C1': {$format = array(1836.85,2599.37); break;}
- case 'C2': {$format = array(1298.27,1836.85); break;}
- case 'C3': {$format = array(918.43,1298.27); break;}
- case 'C4': {$format = array(649.13,918.43); break;}
- case 'C5': {$format = array(459.21,649.13); break;}
- case 'C6': {$format = array(323.15,459.21); break;}
- case 'C7': {$format = array(229.61,323.15); break;}
- case 'C8': {$format = array(161.57,229.61); break;}
- case 'C9': {$format = array(113.39,161.57); break;}
- case 'C10': {$format = array(79.37,113.39); break;}
- case 'RA0': {$format = array(2437.80,3458.27); break;}
- case 'RA1': {$format = array(1729.13,2437.80); break;}
- case 'RA2': {$format = array(1218.90,1729.13); break;}
- case 'RA3': {$format = array(864.57,1218.90); break;}
- case 'RA4': {$format = array(609.45,864.57); break;}
- case 'SRA0': {$format = array(2551.18,3628.35); break;}
- case 'SRA1': {$format = array(1814.17,2551.18); break;}
- case 'SRA2': {$format = array(1275.59,1814.17); break;}
- case 'SRA3': {$format = array(907.09,1275.59); break;}
- case 'SRA4': {$format = array(637.80,907.09); break;}
- case 'LETTER': {$format = array(612.00,792.00); break;}
- case 'LEGAL': {$format = array(612.00,1008.00); break;}
- case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
- case 'FOLIO': {$format = array(612.00,936.00); break;}
- // default: {$this->Error('Unknown page format: '.$format); break;}
- // END CHANGES Nicola Asuni
- }
- $this->fwPt=$format[0];
- $this->fhPt=$format[1];
- }
- else {
- $this->fwPt=$format[0]*$this->k;
- $this->fhPt=$format[1]*$this->k;
- }
-
- $this->fw=$this->fwPt/$this->k;
- $this->fh=$this->fhPt/$this->k;
-
- //Page orientation
- $orientation=strtolower($orientation);
- if($orientation=='p' or $orientation=='portrait') {
- $this->DefOrientation='P';
- $this->wPt=$this->fwPt;
- $this->hPt=$this->fhPt;
- }
- elseif($orientation=='l' or $orientation=='landscape') {
- $this->DefOrientation='L';
- $this->wPt=$this->fhPt;
- $this->hPt=$this->fwPt;
- }
- else {
- $this->Error('Incorrect orientation: '.$orientation);
- }
-
- $this->CurOrientation=$this->DefOrientation;
- $this->w=$this->wPt/$this->k;
- $this->h=$this->hPt/$this->k;
- //Page margins (1 cm)
- $margin=28.35/$this->k;
- $this->SetMargins($margin,$margin);
- //Interior cell margin (1 mm)
- $this->cMargin=$margin/10;
- //Line width (0.2 mm)
- $this->LineWidth=.567/$this->k;
- //Automatic page break
- $this->SetAutoPageBreak(true,2*$margin);
- //Full width display mode
- $this->SetDisplayMode('fullwidth');
- //Compression
- $this->SetCompression(true);
- //Set default PDF version number
- $this->PDFVersion = "1.3";
-
- $this->encoding = $encoding;
- $this->b = 0;
- $this->i = 0;
- $this->u = 0;
- $this->HREF = '';
- $this->fontlist = array("arial", "times", "courier", "helvetica", "symbol");
- $this->issetfont = false;
- $this->issetcolor = false;
- $this->tableborder = 0;
- $this->tdbegin = false;
- $this->tdwidth= 0;
- $this->tdheight = 0;
- $this->tdalign = "L";
- $this->tdbgcolor = false;
-
- $this->SetFillColor(200, 200, 200, true);
- $this->SetTextColor(0, 0, 0, true);
- }
-
- /**
- * Set the image scale.
- * @param float $scale image scale.
- * @author Nicola Asuni
- * @since 1.5.2
- */
- function setImageScale($scale) {
- $this->imgscale=$scale;
- }
-
- /**
- * Returns the image scale.
- * @return float image scale.
- * @author Nicola Asuni
- * @since 1.5.2
- */
- function getImageScale() {
- return $this->imgscale;
- }
-
- /**
- * Returns the page width in units.
- * @return int page width.
- * @author Nicola Asuni
- * @since 1.5.2
- */
- function getPageWidth() {
- return $this->w;
- }
-
- /**
- * Returns the page height in units.
- * @return int page height.
- * @author Nicola Asuni
- * @since 1.5.2
- */
- function getPageHeight() {
- return $this->fh;
- }
-
- /**
- * Returns the page break margin.
- * @return int page break margin.
- * @author Nicola Asuni
- * @since 1.5.2
- */
- function getBreakMargin() {
- return $this->bMargin;
- }
-
- /**
- * Returns the scale factor (number of points in user unit).
- * @return int scale factor.
- * @author Nicola Asuni
- * @since 1.5.2
- */
- function getScaleFactor() {
- return $this->k;
- }
-
- /**
- * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
- * @param float $left Left margin.
- * @param float $top Top margin.
- * @param float $right Right margin. Default value is the left one.
- * @since 1.0
- * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
- */
- function SetMargins($left, $top, $right=-1) {
- //Set left, top and right margins
- $this->lMargin=$left;
- $this->tMargin=$top;
- if($right==-1) {
- $right=$left;
- }
- $this->rMargin=$right;
- }
-
- /**
- * 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.
- * @param float $margin The margin.
- * @since 1.4
- * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
- */
- function SetLeftMargin($margin) {
- //Set left margin
- $this->lMargin=$margin;
- if(($this->page>0) and ($this->x<$margin)) {
- $this->x=$margin;
- }
- }
-
- /**
- * Defines the top margin. The method can be called before creating the first page.
- * @param float $margin The margin.
- * @since 1.5
- * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
- */
- function SetTopMargin($margin) {
- //Set top margin
- $this->tMargin=$margin;
- }
-
- /**
- * Defines the right margin. The method can be called before creating the first page.
- * @param float $margin The margin.
- * @since 1.5
- * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
- */
- function SetRightMargin($margin) {
- //Set right margin
- $this->rMargin=$margin;
- }
-
- /**
- * 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.
- * @param boolean $auto Boolean indicating if mode should be on or off.
- * @param float $margin Distance from the bottom of the page.
- * @since 1.0
- * @see Cell(), MultiCell(), AcceptPageBreak()
- */
- function SetAutoPageBreak($auto, $margin=0) {
- //Set auto page break mode and triggering margin
- $this->AutoPageBreak=$auto;
- $this->bMargin=$margin;
- $this->PageBreakTrigger=$this->h-$margin;
- }
-
- /**
- * 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.
- * @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>
- * @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>
- * @since 1.2
- */
- function SetDisplayMode($zoom, $layout='continuous') {
- //Set display mode in viewer
- if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
- $this->ZoomMode=$zoom;
- }
- else {
- $this->Error('Incorrect zoom display mode: '.$zoom);
- }
- if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') {
- $this->LayoutMode=$layout;
- }
- else {
- $this->Error('Incorrect layout display mode: '.$layout);
- }
- }
-
- /**
- * 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.
- * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
- * @param boolean $compress Boolean indicating if compression must be enabled.
- * @since 1.4
- */
- function SetCompression($compress) {
- //Set page compression
- if(function_exists('gzcompress')) {
- $this->compress=$compress;
- }
- else {
- $this->compress=false;
- }
- }
-
- /**
- * Defines the title of the document.
- * @param string $title The title.
- * @since 1.2
- * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
- */
- function SetTitle($title) {
- //Title of document
- $this->title=$title;
- }
-
- /**
- * Defines the subject of the document.
- * @param string $subject The subject.
- * @since 1.2
- * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
- */
- function SetSubject($subject) {
- //Subject of document
- $this->subject=$subject;
- }
-
- /**
- * Defines the author of the document.
- * @param string $author The name of the author.
- * @since 1.2
- * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
- */
- function SetAuthor($author) {
- //Author of document
- $this->author=$author;
- }
-
- /**
- * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
- * @param string $keywords The list of keywords.
- * @since 1.2
- * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
- */
- function SetKeywords($keywords) {
- //Keywords of document
- $this->keywords=$keywords;
- }
-
- /**
- * Defines the creator of the document. This is typically the name of the application that generates the PDF.
- * @param string $creator The name of the creator.
- * @since 1.2
- * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
- */
- function SetCreator($creator) {
- //Creator of document
- $this->creator=$creator;
- }
-
- /**
- * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
- * <b>Example:</b><br />
- * <pre>
- * class PDF extends TCPDF {
- * function Footer() {
- * //Go to 1.5 cm from bottom
- * $this->SetY(-15);
- * //Select Arial italic 8
- * $this->SetFont('Arial','I',8);
- * //Print current and total page numbers
- * $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
- * }
- * }
- * $pdf=new PDF();
- * $pdf->AliasNbPages();
- * </pre>
- * @param string $alias The alias. Default value: {nb}.
- * @since 1.4
- * @see PageNo(), Footer()
- */
- function AliasNbPages($alias='{nb}') {
- //Define an alias for total number of pages
- $this->AliasNbPages = $this->_escapetext($alias);
- }
-
- /**
- * 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.
- * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
- * @param string $msg The error message
- * @since 1.0
- */
- function Error($msg) {
- //Fatal error
- die('<strong>TCPDF error: </strong>'.$msg);
- }
-
- /**
- * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
- * Note: no page is created by this method
- * @since 1.0
- * @see AddPage(), Close()
- */
- function Open() {
- //Begin document
- $this->state=1;
- }
-
- /**
- * 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.
- * @since 1.0
- * @see Open(), Output()
- */
- function Close() {
- //Terminate document
- if($this->state==3) {
- return;
- }
- if($this->page==0) {
- $this->AddPage();
- }
- //Page footer
- $this->InFooter=true;
- $this->Footer();
- $this->InFooter=false;
- //Close page
- $this->_endpage();
- //Close document
- $this->_enddoc();
- }
-
- /**
- * 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.
- * 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.
- * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
- * @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.
- * @since 1.0
- * @see TCPDF(), Header(), Footer(), SetMargins()
- */
- function AddPage($orientation='') {
- //Start a new page
- if($this->state==0) {
- $this->Open();
- }
- $family=$this->FontFamily;
- $style=$this->FontStyle.($this->underline ? 'U' : '');
- $size=$this->FontSizePt;
- $lw=$this->LineWidth;
- $dc=$this->DrawColor;
- $fc=$this->FillColor;
- $tc=$this->TextColor;
- $cf=$this->ColorFlag;
- if($this->page>0) {
- //Page footer
- $this->InFooter=true;
- $this->Footer();
- $this->InFooter=false;
- //Close page
- $this->_endpage();
- }
- //Start new page
- $this->_beginpage($orientation);
- //Set line cap style to square
- $this->_out('2 J');
- //Set line width
- $this->LineWidth=$lw;
- $this->_out(sprintf('%.2f w',$lw*$this->k));
- //Set font
- if($family) {
- $this->SetFont($family,$style,$size);
- }
- //Set colors
- $this->DrawColor=$dc;
- if($dc!='0 G') {
- $this->_out($dc);
- }
- $this->FillColor=$fc;
- if($fc!='0 g') {
- $this->_out($fc);
- }
- $this->TextColor=$tc;
- $this->ColorFlag=$cf;
- //Page header
- $this->Header();
- //Restore line width
- if($this->LineWidth!=$lw) {
- $this->LineWidth=$lw;
- $this->_out(sprintf('%.2f w',$lw*$this->k));
- }
- //Restore font
- if($family) {
- $this->SetFont($family,$style,$size);
- }
- //Restore colors
- if($this->DrawColor!=$dc) {
- $this->DrawColor=$dc;
- $this->_out($dc);
- }
- if($this->FillColor!=$fc) {
- $this->FillColor=$fc;
- $this->_out($fc);
- }
- $this->TextColor=$tc;
- $this->ColorFlag=$cf;
- }
-
-
-
- /**
- * Set header data.
- * @param string $ln header image logo
- * @param string $lw header image logo width in mm
- * @param string $ht string to print as title on document header
- * @param string $hs string to print on document header
- */
- function setHeaderData($ln="", $lw=0, $ht="", $hs="") {
- $this->header_logo = $ln;
- $this->header_logo_width = $lw;
- $this->header_title = $ht;
- $this->header_string = $hs;
- }
-
- /**
- * Set header margin.
- * (minimum distance between header and top page margin)
- * @param int $hm distance in millimeters
- */
- function setHeaderMargin($hm=10) {
- $this->header_margin = $hm;
- }
-
- /**
- * Set footer margin.
- * (minimum distance between footer and bottom page margin)
- * @param int $fm distance in millimeters
- */
- function setFooterMargin($fm=10) {
- $this->footer_margin = $fm;
- }
-
- /**
- * This method is used to render the page header.
- * It is automatically called by AddPage() and could be overwritten in your own inherited class.
- */
- function Header() {
- if ($this->print_header) {
-
- if (!isset($this->original_lMargin)) {
- $this->original_lMargin = $this->lMargin;
- }
- if (!isset($this->original_rMargin)) {
- $this->original_rMargin = $this->rMargin;
- }
-
- //set current position
- $this->SetXY($this->original_lMargin, $this->header_margin);
-
- if (($this->header_logo) AND ($this->header_logo != K_BLANK_IMAGE)) {
- $this->Image(K_PATH_IMAGES.$this->header_logo, $this->original_lMargin, $this->header_margin, $this->header_logo_width);
- }
- else {
- $this->img_rb_y = $this->GetY();
- }
-
- $cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2);
-
- $header_x = $this->original_lMargin + ($this->header_logo_width * 1.05); //set left margin for text data cell
-
- // header title
- $this->SetFont($this->header_font[0], 'B', $this->header_font[2] + 1);
- $this->SetX($header_x);
- $this->Cell($this->header_width, $cell_height, $this->header_title, 0, 1, 'L');
-
- // header string
- $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
- $this->SetX($header_x);
- $this->MultiCell($this->header_width, $cell_height, $this->header_string, 0, 'L', 0);
-
- // print an ending header line
- if (empty($this->header_width)) {
- //set style for cell border
- $this->SetLineWidth(0.3);
- $this->SetDrawColor(0, 0, 0);
- $this->SetY(1 + max($this->img_rb_y, $this->GetY()));
- $this->SetX($this->original_lMargin);
- $this->Cell(0, 0, '', 'T', 0, 'C');
- }
-
- //restore position
- $this->SetXY($this->original_lMargin, $this->tMargin);
- }
- }
-
- /**
- * This method is used to render the page footer.
- * It is automatically called by AddPage() and could be overwritten in your own inherited class.
- */
- function Footer() {
- if ($this->print_footer) {
-
- if (!isset($this->original_lMargin)) {
- $this->original_lMargin = $this->lMargin;
- }
- if (!isset($this->original_rMargin)) {
- $this->original_rMargin = $this->rMargin;
- }
-
- //set font
- $this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]);
- //set style for cell border
- $line_width = 0.3;
- $this->SetLineWidth($line_width);
- $this->SetDrawColor(0, 0, 0);
-
- $footer_height = round((K_CELL_HEIGHT_RATIO * $this->footer_font[2]) / $this->k, 2); //footer height
- //get footer y position
- $footer_y = $this->h - $this->footer_margin - $footer_height;
- //set current position
- $this->SetXY($this->original_lMargin, $footer_y);
-
- //print document barcode
- if ($this->barcode) {
- $this->Ln();
- $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin)); //max width
- $this->writeBarcode($this->original_lMargin, $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode);
- }
-
- $this->SetXY($this->original_lMargin, $footer_y);
-
- //Print page number
- $this->Cell(0, $footer_height, $this->l['w_page']." ".$this->PageNo().' / {nb}', 'T', 0, 'R');
- }
- }
-
- /**
- * Returns the current page number.
- * @return int page number
- * @since 1.0
- * @see AliasNbPages()
- */
- function PageNo() {
- //Get current page number
- return $this->page;
- }
-
- /**
- * 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.
- * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
- *…
Large files files are truncated, but you can click here to view the full file