linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file tcpdf.php

Documentation is available at tcpdf.php

  1. <?php
  2. //============================================================+
  3. // File name   : tcpdf.php
  4. // Begin       : 2002-08-03
  5. // Last Update : 2007-03-20
  6. // Author      : Nicola Asuni
  7. // Version     : 1.53.0.TC031
  8. // License     : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9. //
  10. // Description : This is a PHP5 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. //    PHP5 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.  * TCPDF Class.
  34.  * @package linea21.externals
  35.  * @subpackage com.tecnick.tcpdf
  36.  */
  37.  
  38. /**
  39.  * include configuration file
  40.  */
  41. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  42.  
  43. /**
  44.  * This is a PHP5 class for generating PDF files on-the-fly without requiring external extensions.<br>
  45.  * TCPDF project (http://tcpdf.sourceforge.net) is based on the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  46.  * <h3>TCPDF main changes from FPDF are:</h3><ul>
  47.  * <li>PHP5 porting</li>
  48.  * <li>UTF-8 Unicode support</li>
  49.  * <li>source code clean up</li>
  50.  * <li>code style and formatting</li>
  51.  * <li>source code documentation using phpDocumentor (www.phpdoc.org)</li>
  52.  * <li>All ISO page formats were included</li>
  53.  * <li>image scale factor</li>
  54.  * <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>
  55.  * <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>
  56.  * <li>defines standard Header() and Footer() methods.</li>
  57.  * </ul>
  58.  * Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p>
  59.  * @name TCPDF
  60.  * @package linea21.externals
  61.  * @subpackage 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.TC031
  68.  */
  69.  
  70. if(!class_exists('TCPDF'false)) {
  71.     /**
  72.      * define default PDF document producer
  73.      */ 
  74.     define('PDF_PRODUCER','TCPDF 1.53.0.TC031 (http://tcpdf.sourceforge.net)');
  75.     
  76.     /**
  77.     * This is a PHP5 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 PHP5, 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 linea21.externals
  84.     * @subpackage com.tecnick.tcpdf
  85.     * @version 1.53.0.TC031
  86.     * @author Nicola Asuni
  87.     * @link http://tcpdf.sourceforge.net
  88.     * @license http://www.gnu.org/copyleft/lesser.html LGPL
  89.     */
  90.     class TCPDF {
  91.         //Private properties
  92.  
  93.         /**
  94.         * @var current page number
  95.         * @access protected
  96.         */
  97.         protected $page;
  98.  
  99.         /**
  100.         * @var current object number
  101.         * @access protected
  102.         */
  103.         protected $n;
  104.  
  105.         /**
  106.         * @var array of object offsets
  107.         * @access protected
  108.         */
  109.         protected $offsets;
  110.  
  111.         /**
  112.         * @var buffer holding in-memory PDF
  113.         * @access protected
  114.         */
  115.         protected $buffer;
  116.  
  117.         /**
  118.         * @var array containing pages
  119.         * @access protected
  120.         */
  121.         protected $pages;
  122.  
  123.         /**
  124.         * @var current document state
  125.         * @access protected
  126.         */
  127.         protected $state;
  128.  
  129.         /**
  130.         * @var compression flag
  131.         * @access protected
  132.         */
  133.         protected $compress;
  134.  
  135.         /**
  136.         * @var default orientation
  137.         * @access protected
  138.         */
  139.         protected $DefOrientation;
  140.  
  141.         /**
  142.         * @var current orientation
  143.         * @access protected
  144.         */
  145.         protected $CurOrientation;
  146.  
  147.         /**
  148.         * @var array indicating orientation changes
  149.         * @access protected
  150.         */
  151.         protected $OrientationChanges;
  152.  
  153.         /**
  154.         * @var scale factor (number of points in user unit)
  155.         * @access protected
  156.         */
  157.         protected $k;
  158.  
  159.         /**
  160.         * @var width of page format in points
  161.         * @access protected
  162.         */
  163.         protected $fwPt;
  164.  
  165.         /**
  166.         * @var height of page format in points
  167.         * @access protected
  168.         */
  169.         protected $fhPt;
  170.  
  171.         /**
  172.         * @var width of page format in user unit
  173.         * @access protected
  174.         */
  175.         protected $fw;
  176.  
  177.         /**
  178.         * @var height of page format in user unit
  179.         * @access protected
  180.         */
  181.         protected $fh;
  182.  
  183.         /**
  184.         * @var current width of page in points
  185.         * @access protected
  186.         */
  187.         protected $wPt;
  188.  
  189.         /**
  190.         * @var current height of page in points
  191.         * @access protected
  192.         */
  193.         protected $hPt;
  194.  
  195.         /**
  196.         * @var current width of page in user unit
  197.         * @access protected
  198.         */
  199.         protected $w;
  200.  
  201.         /**
  202.         * @var current height of page in user unit
  203.         * @access protected
  204.         */
  205.         protected $h;
  206.  
  207.         /**
  208.         * @var left margin
  209.         * @access protected
  210.         */
  211.         protected $lMargin;
  212.  
  213.         /**
  214.         * @var top margin
  215.         * @access protected
  216.         */
  217.         protected $tMargin;
  218.  
  219.         /**
  220.         * @var right margin
  221.         * @access protected
  222.         */
  223.         protected $rMargin;
  224.  
  225.         /**
  226.         * @var page break margin
  227.         * @access protected
  228.         */
  229.         protected $bMargin;
  230.  
  231.         /**
  232.         * @var cell margin
  233.         * @access protected
  234.         */
  235.         protected $cMargin;
  236.  
  237.         /**
  238.         * @var current horizontal position in user unit for cell positioning
  239.         * @access protected
  240.         */
  241.         protected $x;
  242.  
  243.         /**
  244.         * @var current vertical position in user unit for cell positioning
  245.         * @access protected
  246.         */
  247.         protected $y;
  248.  
  249.         /**
  250.         * @var height of last cell printed
  251.         * @access protected
  252.         */
  253.         protected $lasth;
  254.  
  255.         /**
  256.         * @var line width in user unit
  257.         * @access protected
  258.         */
  259.         protected $LineWidth;
  260.  
  261.         /**
  262.         * @var array of standard font names
  263.         * @access protected
  264.         */
  265.         protected $CoreFonts;
  266.  
  267.         /**
  268.         * @var array of used fonts
  269.         * @access protected
  270.         */
  271.         protected $fonts;
  272.  
  273.         /**
  274.         * @var array of font files
  275.         * @access protected
  276.         */
  277.         protected $FontFiles;
  278.  
  279.         /**
  280.         * @var array of encoding differences
  281.         * @access protected
  282.         */
  283.         protected $diffs;
  284.  
  285.         /**
  286.         * @var array of used images
  287.         * @access protected
  288.         */
  289.         protected $images;
  290.  
  291.         /**
  292.         * @var array of links in pages
  293.         * @access protected
  294.         */
  295.         protected $PageLinks;
  296.  
  297.         /**
  298.         * @var array of internal links
  299.         * @access protected
  300.         */
  301.         protected $links;
  302.  
  303.         /**
  304.         * @var current font family
  305.         * @access protected
  306.         */
  307.         protected $FontFamily;
  308.  
  309.         /**
  310.         * @var current font style
  311.         * @access protected
  312.         */
  313.         protected $FontStyle;
  314.  
  315.         /**
  316.         * @var underlining flag
  317.         * @access protected
  318.         */
  319.         protected $underline;
  320.  
  321.         /**
  322.         * @var current font info
  323.         * @access protected
  324.         */
  325.         protected $CurrentFont;
  326.  
  327.         /**
  328.         * @var current font size in points
  329.         * @access protected
  330.         */
  331.         protected $FontSizePt;
  332.  
  333.         /**
  334.         * @var current font size in user unit
  335.         * @access protected
  336.         */
  337.         protected $FontSize;
  338.  
  339.         /**
  340.         * @var commands for drawing color
  341.         * @access protected
  342.         */
  343.         protected $DrawColor;
  344.  
  345.         /**
  346.         * @var commands for filling color
  347.         * @access protected
  348.         */
  349.         protected $FillColor;
  350.  
  351.         /**
  352.         * @var commands for text color
  353.         * @access protected
  354.         */
  355.         protected $TextColor;
  356.  
  357.         /**
  358.         * @var indicates whether fill and text colors are different
  359.         * @access protected
  360.         */
  361.         protected $ColorFlag;
  362.  
  363.         /**
  364.         * @var word spacing
  365.         * @access protected
  366.         */
  367.         protected $ws;
  368.  
  369.         /**
  370.         * @var automatic page breaking
  371.         * @access protected
  372.         */
  373.         protected $AutoPageBreak;
  374.  
  375.         /**
  376.         * @var threshold used to trigger page breaks
  377.         * @access protected
  378.         */
  379.         protected $PageBreakTrigger;
  380.  
  381.         /**
  382.         * @var flag set when processing footer
  383.         * @access protected
  384.         */
  385.         protected $InFooter;
  386.  
  387.         /**
  388.         * @var zoom display mode
  389.         * @access protected
  390.         */
  391.         protected $ZoomMode;
  392.  
  393.         /**
  394.         * @var layout display mode
  395.         * @access protected
  396.         */
  397.         protected $LayoutMode;
  398.  
  399.         /**
  400.         * @var title 
  401.         * @access protected
  402.         */
  403.         protected $title;
  404.  
  405.         /**
  406.         * @var subject 
  407.         * @access protected
  408.         */
  409.         protected $subject;
  410.  
  411.         /**
  412.         * @var author 
  413.         * @access protected
  414.         */
  415.         protected $author;
  416.  
  417.         /**
  418.         * @var keywords 
  419.         * @access protected
  420.         */
  421.         protected $keywords;
  422.  
  423.         /**
  424.         * @var creator 
  425.         * @access protected
  426.         */
  427.         protected $creator;
  428.  
  429.         /**
  430.         * @var alias for total number of pages
  431.         * @access protected
  432.         */
  433.         protected $AliasNbPages;
  434.  
  435.         /**
  436.         * @var right-bottom corner X coordinate of inserted image
  437.         * @since 2002-07-31
  438.         * @author Nicola Asuni
  439.         * @access protected
  440.         */
  441.         protected $img_rb_x;
  442.  
  443.         /**
  444.         * @var right-bottom corner Y coordinate of inserted image
  445.         * @since 2002-07-31
  446.         * @author Nicola Asuni
  447.         * @access protected
  448.         */
  449.         protected $img_rb_y;
  450.  
  451.         /**
  452.         * @var image scale factor
  453.         * @since 2004-06-14
  454.         * @author Nicola Asuni
  455.         * @access protected
  456.         */
  457.         protected $imgscale = 1;
  458.  
  459.         /**
  460.         * @var boolean set to true when the input text is unicode (require unicode fonts)
  461.         * @since 2005-01-02
  462.         * @author Nicola Asuni
  463.         * @access protected
  464.         */
  465.         protected $isunicode = false;
  466.  
  467.         /**
  468.         * @var PDF version
  469.         * @since 1.5.3
  470.         * @access protected
  471.         */
  472.         protected $PDFVersion = "1.3";
  473.         
  474.         
  475.         // ----------------------
  476.         
  477.         /**
  478.          * @var Minimum distance between header and top page margin.
  479.          * @access private
  480.          */
  481.         private $header_margin;
  482.         
  483.         /**
  484.          * @var Minimum distance between footer and bottom page margin.
  485.          * @access private
  486.          */
  487.         private $footer_margin;
  488.         
  489.         /**
  490.          * @var original left margin value
  491.          * @access private
  492.          * @since 1.53.0.TC013
  493.          */
  494.         private $original_lMargin;
  495.         
  496.         /**
  497.          * @var original right margin value
  498.          * @access private
  499.          * @since 1.53.0.TC013
  500.          */
  501.         private $original_rMargin;
  502.             
  503.         /**
  504.          * @var Header font.
  505.          * @access private
  506.          */
  507.         private $header_font;
  508.         
  509.         /**
  510.          * @var Footer font.
  511.          * @access private
  512.          */
  513.         private $footer_font;
  514.         
  515.         /**
  516.          * @var Language templates.
  517.          * @access private
  518.          */
  519.         private $l;
  520.         
  521.         /**
  522.          * @var Barcode to print on page footer (only if set).
  523.          * @access private
  524.          */
  525.         private $barcode false;
  526.         
  527.         /**
  528.          * @var If true prints header
  529.          * @access private
  530.          */
  531.         private $print_header true;
  532.         
  533.         /**
  534.          * @var If true prints footer.
  535.          * @access private
  536.          */
  537.         private $print_footer true;
  538.         
  539.         /**
  540.          * @var Header width (0 = full page width).
  541.          * @access private
  542.          */
  543.         private $header_width 0;
  544.         
  545.         /**
  546.          * @var Header image logo.
  547.          * @access private
  548.          */
  549.         private $header_logo "";
  550.         
  551.         /**
  552.          * @var Header image logo width in mm.
  553.          * @access private
  554.          */
  555.         private $header_logo_width 30;
  556.         
  557.         /**
  558.          * @var String to print as title on document header.
  559.          * @access private
  560.          */
  561.         private $header_title "";
  562.         
  563.         /**
  564.          * @var String to print on document header.
  565.          * @access private
  566.          */
  567.         private $header_string "";
  568.         
  569.         /**
  570.          * @var Default number of columns for html table.
  571.          * @access private
  572.          */
  573.         private $default_table_columns 4;
  574.         
  575.         
  576.         // variables for html parser
  577.         
  578.         /**
  579.          * @var HTML PARSER: store current link.
  580.          * @access private
  581.          */
  582.         private $HREF;
  583.         
  584.         /**
  585.          * @var HTML PARSER: store font list.
  586.          * @access private
  587.          */
  588.         private $fontList;
  589.         
  590.         /**
  591.          * @var HTML PARSER: true when font attribute is set.
  592.          * @access private
  593.          */
  594.         private $issetfont;
  595.         
  596.         /**
  597.          * @var HTML PARSER: true when color attribute is set.
  598.          * @access private
  599.          */
  600.         private $issetcolor;
  601.         
  602.         /**
  603.          * @var HTML PARSER: true in case of ordered list (OL), false otherwise.
  604.          * @access private
  605.          */
  606.         private $listordered false;
  607.         
  608.         /**
  609.          * @var HTML PARSER: count list items.
  610.          * @access private
  611.          */
  612.         private $listcount 0;
  613.         
  614.         /**
  615.          * @var HTML PARSER: size of table border.
  616.          * @access private
  617.          */
  618.         private $tableborder 0;
  619.         
  620.         /**
  621.          * @var HTML PARSER: true at the beginning of table.
  622.          * @access private
  623.          */
  624.         private $tdbegin false;
  625.         
  626.         /**
  627.          * @var HTML PARSER: table width.
  628.          * @access private
  629.          */
  630.         private $tdwidth 0;
  631.         
  632.         /**
  633.          * @var HTML PARSER: table height.
  634.          * @access private
  635.          */
  636.         private $tdheight 0;
  637.         
  638.         /**
  639.          * @var HTML PARSER: table align.
  640.          * @access private
  641.          */
  642.         private $tdalign "L";
  643.         
  644.         /**
  645.          * @var HTML PARSER: table background color.
  646.          * @access private
  647.          */
  648.         private $tdbgcolor false;
  649.         
  650.         /**
  651.          * @var Store temporary font size in points.
  652.          * @access private
  653.          */
  654.         private $tempfontsize 10;
  655.         
  656.         /**
  657.          * @var Bold font style status.
  658.          * @access private
  659.          */
  660.         private $b;
  661.         
  662.         /**
  663.          * @var Underlined font style status.
  664.          * @access private
  665.          */
  666.         private $u;
  667.         
  668.         /**
  669.          * @var Italic font style status.
  670.          * @access private
  671.          */
  672.         private $i;
  673.         
  674.         /**
  675.          * @var spacer for LI tags.
  676.          * @access private
  677.          */
  678.         private $lispacer "";
  679.         
  680.         /**
  681.          * @var default encoding
  682.          * @access private
  683.          * @since 1.53.0.TC010
  684.          */
  685.         private $encoding "UTF-8";
  686.         
  687.         /**
  688.          * @var PHP internal encoding
  689.          * @access private
  690.          * @since 1.53.0.TC016
  691.          */
  692.         private $internal_encoding;
  693.         
  694.         /**
  695.          * @var store previous fill color as RGB array
  696.          * @access private
  697.          * @since 1.53.0.TC017
  698.          */
  699.         private $prevFillColor array(255,255,255);
  700.         
  701.         /**
  702.          * @var store previous text color as RGB array
  703.          * @access private
  704.          * @since 1.53.0.TC017
  705.          */
  706.         private $prevTextColor array(0,0,0);
  707.         
  708.         /**
  709.          * @var store previous font family
  710.          * @access private
  711.          * @since 1.53.0.TC017
  712.          */
  713.         private $prevFontFamily;
  714.         
  715.         /**
  716.          * @var store previous font style
  717.          * @access private
  718.          * @since 1.53.0.TC017
  719.          */
  720.         private $prevFontStyle;
  721.         
  722.  
  723.         //------------------------------------------------------------
  724.         // Public methods
  725.         //------------------------------------------------------------
  726.  
  727.         /**
  728.          * This is the class constructor.
  729.          * It allows to set up the page format, the orientation and
  730.          * the measure unit used in all the methods (except for the font sizes).
  731.          * @since 1.0
  732.          * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  733.          * @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.
  734.          * @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>
  735.          * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  736.          * @param String $encoding charset encoding; default is UTF-8
  737.          */
  738.         public function __construct($orientation='P'$unit='mm'$format='A4'$unicode=true$encoding="UTF-8"{
  739.             
  740.             /* Set internal character encoding to ASCII */
  741.             if (function_exists("mb_internal_encoding"AND mb_internal_encoding()) {
  742.                 $this->internal_encoding mb_internal_encoding();
  743.                 mb_internal_encoding("ASCII");
  744.             }
  745.                 
  746.             //Some checks
  747.             $this->_dochecks();
  748.             //Initialization of properties
  749.             $this->isunicode=$unicode;
  750.             $this->page=0;
  751.             $this->n=2;
  752.             $this->buffer='';
  753.             $this->pages=array();
  754.             $this->OrientationChanges=array();
  755.             $this->state=0;
  756.             $this->fonts=array();
  757.             $this->FontFiles=array();
  758.             $this->diffs=array();
  759.             $this->images=array();
  760.             $this->links=array();
  761.             $this->InFooter=false;
  762.             $this->lasth=0;
  763.             $this->FontFamily='';
  764.             $this->FontStyle='';
  765.             $this->FontSizePt=12;
  766.             $this->underline=false;
  767.             $this->DrawColor='0 G';
  768.             $this->FillColor='0 g';
  769.             $this->TextColor='0 g';
  770.             $this->ColorFlag=false;
  771.             $this->ws=0;
  772.             //Standard Unicode fonts
  773.             $this->CoreFonts=array(
  774.             'courier'=>'Courier',
  775.             'courierB'=>'Courier-Bold',
  776.             'courierI'=>'Courier-Oblique',
  777.             'courierBI'=>'Courier-BoldOblique',
  778.             'helvetica'=>'Helvetica',
  779.             'helveticaB'=>'Helvetica-Bold',
  780.             'helveticaI'=>'Helvetica-Oblique',
  781.             'helveticaBI'=>'Helvetica-BoldOblique',
  782.             'times'=>'Times-Roman',
  783.             'timesB'=>'Times-Bold',
  784.             'timesI'=>'Times-Italic',
  785.             'timesBI'=>'Times-BoldItalic',
  786.             'symbol'=>'Symbol',
  787.             'zapfdingbats'=>'ZapfDingbats'
  788.             );
  789.  
  790.             //Scale factor
  791.             switch (strtolower($unit)){
  792.                 case 'pt'{$this->k=1break;}
  793.                 case 'mm'{$this->k=72/25.4break;}
  794.                 case 'cm'{$this->k=72/2.54break;}
  795.                 case 'in'{$this->k=72break;}
  796.                 default {$this->Error('Incorrect unit: '.$unit)break;}
  797.             }
  798.  
  799.             //Page format
  800.             if(is_string($format)) {
  801.                 // 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.                 }
  855.                 $this->fwPt=$format[0];
  856.                 $this->fhPt=$format[1];
  857.             }
  858.             else {
  859.                 $this->fwPt=$format[0]*$this->k;
  860.                 $this->fhPt=$format[1]*$this->k;
  861.             }
  862.  
  863.             $this->fw=$this->fwPt/$this->k;
  864.             $this->fh=$this->fhPt/$this->k;
  865.  
  866.             //Page orientation
  867.             $orientation=strtolower($orientation);
  868.             if($orientation=='p' or $orientation=='portrait'{
  869.                 $this->DefOrientation='P';
  870.                 $this->wPt=$this->fwPt;
  871.                 $this->hPt=$this->fhPt;
  872.             }
  873.             elseif($orientation=='l' or $orientation=='landscape'{
  874.                 $this->DefOrientation='L';
  875.                 $this->wPt=$this->fhPt;
  876.                 $this->hPt=$this->fwPt;
  877.             }
  878.             else {
  879.                 $this->Error('Incorrect orientation: '.$orientation);
  880.             }
  881.  
  882.             $this->CurOrientation=$this->DefOrientation;
  883.             $this->w=$this->wPt/$this->k;
  884.             $this->h=$this->hPt/$this->k;
  885.             //Page margins (1 cm)
  886.             $margin=28.35/$this->k;
  887.             $this->SetMargins($margin,$margin);
  888.             //Interior cell margin (1 mm)
  889.             $this->cMargin=$margin/10;
  890.             //Line width (0.2 mm)
  891.             $this->LineWidth=.567/$this->k;
  892.             //Automatic page break
  893.             $this->SetAutoPageBreak(true,2*$margin);
  894.             //Full width display mode
  895.             $this->SetDisplayMode('fullwidth');
  896.             //Compression
  897.             $this->SetCompression(true);
  898.             //Set default PDF version number
  899.             $this->PDFVersion = "1.3";
  900.             
  901.             $this->encoding $encoding;
  902.             $this->0;
  903.             $this->0;
  904.             $this->0;
  905.             $this->HREF '';
  906.             $this->fontlist array("arial""times""courier""helvetica""symbol");
  907.             $this->issetfont false;
  908.             $this->issetcolor false;
  909.             $this->tableborder 0;
  910.             $this->tdbegin false;
  911.             $this->tdwidth=  0;
  912.             $this->tdheight 0;
  913.             $this->tdalign "L";
  914.             $this->tdbgcolor false;
  915.             
  916.             $this->SetFillColor(200200200true);
  917.             $this->SetTextColor(000true);
  918.         }
  919.         
  920.         /**
  921.          * Default destructor.
  922.          * @since 1.53.0.TC016
  923.          */
  924.         public function __destruct({
  925.             // restore internal encoding
  926.             if (isset($this->internal_encodingAND !empty($this->internal_encoding)) {
  927.                 mb_internal_encoding($this->internal_encoding);
  928.             }
  929.         }
  930.  
  931.         /**
  932.         * Set the image scale.
  933.         * @param float $scale image scale.
  934.         * @author Nicola Asuni
  935.         * @since 1.5.2
  936.         */
  937.         public function setImageScale($scale{
  938.             $this->imgscale=$scale;
  939.         }
  940.  
  941.         /**
  942.         * Returns the image scale.
  943.         * @return float image scale.
  944.         * @author Nicola Asuni
  945.         * @since 1.5.2
  946.         */
  947.         public function getImageScale({
  948.             return $this->imgscale;
  949.         }
  950.  
  951.         /**
  952.         * Returns the page width in units.
  953.         * @return int page width.
  954.         * @author Nicola Asuni
  955.         * @since 1.5.2
  956.         */
  957.         public function getPageWidth({
  958.             return $this->w;
  959.         }
  960.  
  961.         /**
  962.         * Returns the page height in units.
  963.         * @return int page height.
  964.         * @author Nicola Asuni
  965.         * @since 1.5.2
  966.         */
  967.         public function getPageHeight({
  968.             return $this->h;
  969.         }
  970.  
  971.         /**
  972.         * Returns the page break margin.
  973.         * @return int page break margin.
  974.         * @author Nicola Asuni
  975.         * @since 1.5.2
  976.         */
  977.         public function getBreakMargin({
  978.             return $this->bMargin;
  979.         }
  980.  
  981.         /**
  982.         * Returns the scale factor (number of points in user unit).
  983.         * @return int scale factor.
  984.         * @author Nicola Asuni
  985.         * @since 1.5.2
  986.         */
  987.         public function getScaleFactor({
  988.             return $this->k;
  989.         }
  990.  
  991.         /**
  992.         * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
  993.         * @param float $left Left margin.
  994.         * @param float $top Top margin.
  995.         * @param float $right Right margin. Default value is the left one.
  996.         * @since 1.0
  997.         * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  998.         */
  999.         public function SetMargins($left$top$right=-1{
  1000.             //Set left, top and right margins
  1001.             $this->lMargin=$left;
  1002.             $this->tMargin=$top;
  1003.             if($right==-1{
  1004.                 $right=$left;
  1005.             }
  1006.             $this->rMargin=$right;
  1007.         }
  1008.  
  1009.         /**
  1010.         * 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.
  1011.         * @param float $margin The margin.
  1012.         * @since 1.4
  1013.         * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1014.         */
  1015.         public function SetLeftMargin($margin{
  1016.             //Set left margin
  1017.             $this->lMargin=$margin;
  1018.             if(($this->page>0and ($this->x<$margin)) {
  1019.                 $this->x=$margin;
  1020.             }
  1021.         }
  1022.  
  1023.         /**
  1024.         * Defines the top margin. The method can be called before creating the first page.
  1025.         * @param float $margin The margin.
  1026.         * @since 1.5
  1027.         * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1028.         */
  1029.         public function SetTopMargin($margin{
  1030.             //Set top margin
  1031.             $this->tMargin=$margin;
  1032.         }
  1033.  
  1034.         /**
  1035.         * Defines the right margin. The method can be called before creating the first page.
  1036.         * @param float $margin The margin.
  1037.         * @since 1.5
  1038.         * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1039.         */
  1040.         public function SetRightMargin($margin{
  1041.             //Set right margin
  1042.             $this->rMargin=$margin;
  1043.         }
  1044.  
  1045.         /**
  1046.         * 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.
  1047.         * @param boolean $auto Boolean indicating if mode should be on or off.
  1048.         * @param float $margin Distance from the bottom of the page.
  1049.         * @since 1.0
  1050.         * @see Cell(), MultiCell(), AcceptPageBreak()
  1051.         */
  1052.         public function SetAutoPageBreak($auto$margin=0{
  1053.             //Set auto page break mode and triggering margin
  1054.             $this->AutoPageBreak=$auto;
  1055.             $this->bMargin=$margin;
  1056.             $this->PageBreakTrigger=$this->h-$margin;
  1057.         }
  1058.  
  1059.         /**
  1060.         * 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.
  1061.         * @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>
  1062.         * @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>
  1063.         * @since 1.2
  1064.         */
  1065.         public function SetDisplayMode($zoom$layout='continuous'{
  1066.             //Set display mode in viewer
  1067.             if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
  1068.                 $this->ZoomMode=$zoom;
  1069.             }
  1070.             else {
  1071.                 $this->Error('Incorrect zoom display mode: '.$zoom);
  1072.             }
  1073.             if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default'{
  1074.                 $this->LayoutMode=$layout;
  1075.             }
  1076.             else {
  1077.                 $this->Error('Incorrect layout display mode: '.$layout);
  1078.             }
  1079.         }
  1080.  
  1081.         /**
  1082.         * 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.
  1083.         * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  1084.         * @param boolean $compress Boolean indicating if compression must be enabled.
  1085.         * @since 1.4
  1086.         */
  1087.         public function SetCompression($compress{
  1088.             //Set page compression
  1089.             if(function_exists('gzcompress')) {
  1090.                 $this->compress=$compress;
  1091.             }
  1092.             else {
  1093.                 $this->compress=false;
  1094.             }
  1095.         }
  1096.  
  1097.         /**
  1098.         * Defines the title of the document.
  1099.         * @param string $title The title.
  1100.         * @since 1.2
  1101.         * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  1102.         */
  1103.         public function SetTitle($title{
  1104.             //Title of document
  1105.             $this->title=$title;
  1106.         }
  1107.  
  1108.         /**
  1109.         * Defines the subject of the document.
  1110.         * @param string $subject The subject.
  1111.         * @since 1.2
  1112.         * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  1113.         */
  1114.         public function SetSubject($subject{
  1115.             //Subject of document
  1116.             $this->subject=$subject;
  1117.         }
  1118.  
  1119.         /**
  1120.         * Defines the author of the document.
  1121.         * @param string $author The name of the author.
  1122.         * @since 1.2
  1123.         * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  1124.         */
  1125.         public function SetAuthor($author{
  1126.             //Author of document
  1127.             $this->author=$author;
  1128.         }
  1129.  
  1130.         /**
  1131.         * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  1132.         * @param string $keywords The list of keywords.
  1133.         * @since 1.2
  1134.         * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  1135.         */
  1136.         public function SetKeywords($keywords{
  1137.             //Keywords of document
  1138.             $this->keywords=$keywords;
  1139.         }
  1140.  
  1141.         /**
  1142.         * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  1143.         * @param string $creator The name of the creator.
  1144.         * @since 1.2
  1145.         * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  1146.         */
  1147.         public function SetCreator($creator{
  1148.             //Creator of document
  1149.             $this->creator=$creator;
  1150.         }
  1151.  
  1152.         /**
  1153.         * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
  1154.         * <b>Example:</b><br />
  1155.         * <pre>
  1156.         * class PDF extends TCPDF {
  1157.         *     public function Footer() {
  1158.         *         //Go to 1.5 cm from bottom
  1159.         *         $this->SetY(-15);
  1160.         *         //Select Arial italic 8
  1161.         *         $this->SetFont('Arial','I',8);
  1162.         *         //Print current and total page numbers
  1163.         *         $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  1164.         *     }
  1165.         * }
  1166.         * $pdf=new PDF();
  1167.         * $pdf->AliasNbPages();
  1168.         * </pre>
  1169.         * @param string $alias The alias. Default value: {nb}.
  1170.         * @since 1.4
  1171.         * @see PageNo(), Footer()
  1172.         */
  1173.         public function AliasNbPages($alias='{nb}'{
  1174.             //Define an alias for total number of pages
  1175.             $this->AliasNbPages = $this->_escapetext($alias);
  1176.         }
  1177.  
  1178.         /**
  1179.         * 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.
  1180.         * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  1181.         * @param string $msg The error message
  1182.         * @since 1.0
  1183.         */
  1184.         public function Error($msg{
  1185.             //Fatal error
  1186.             die('<strong>TCPDF error: </strong>'.$msg);
  1187.         }
  1188.  
  1189.         /**
  1190.         * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
  1191.         * Note: no page is created by this method
  1192.         * @since 1.0
  1193.         * @see AddPage(), Close()
  1194.         */
  1195.         public function Open({
  1196.             //Begin document
  1197.             $this->state=1;
  1198.         }
  1199.  
  1200.         /**
  1201.         * 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.
  1202.         * @since 1.0
  1203.         * @see Open(), Output()
  1204.         */
  1205.         public function Close({
  1206.             //Terminate document
  1207.             if($this->state==3{
  1208.                 return;
  1209.             }
  1210.             if($this->page==0{
  1211.                 $this->AddPage();
  1212.             }
  1213.             //Page footer
  1214.             $this->InFooter=true;
  1215.             $this->Footer();
  1216.             $this->InFooter=false;
  1217.             //Close page
  1218.             $this->_endpage();
  1219.             //Close document
  1220.             $this->_enddoc();
  1221.         }
  1222.  
  1223.         /**
  1224.         * 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.
  1225.         * 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.
  1226.         * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  1227.         * @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.
  1228.         * @since 1.0
  1229.         * @see TCPDF(), Header(), Footer(), SetMargins()
  1230.         */
  1231.         public function AddPage($orientation=''{
  1232.             //Start a new page
  1233.             if($this->state==0{
  1234.                 $this->Open();
  1235.             }
  1236.             $family=$this->FontFamily;
  1237.             $style=$this->FontStyle.($this->underline ? 'U' '');
  1238.             $size=$this->FontSizePt;
  1239.             $lw=$this->LineWidth;
  1240.             $dc=$this->DrawColor;
  1241.             $fc=$this->FillColor;
  1242.             $tc=$this->TextColor;
  1243.             $cf=$this->ColorFlag;
  1244.             if($this->page>0{
  1245.                 //Page footer
  1246.                 $this->InFooter=true;
  1247.                 $this->Footer();
  1248.                 $this->InFooter=false;
  1249.                 //Close page
  1250.                 $this->_endpage();
  1251.             }
  1252.             //Start new page
  1253.             $this->_beginpage($orientation);
  1254.             //Set line cap style to square
  1255.             $this->_out('2 J');
  1256.             //Set line width
  1257.             $this->LineWidth=$lw;
  1258.             $this->_out(sprintf('%.2f w',$lw*$this->k));
  1259.             //Set font
  1260.             if($family{
  1261.                 $this->SetFont($family,$style,$size);
  1262.             }
  1263.             //Set colors
  1264.             $this->DrawColor=$dc;
  1265.             if($dc!='0 G'{
  1266.                 $this->_out($dc);
  1267.             }
  1268.             $this->FillColor=$fc;
  1269.             if($fc!='0 g'{
  1270.                 $this->_out($fc);
  1271.             }
  1272.             $this->TextColor=$tc;
  1273.             $this->ColorFlag=$cf;
  1274.             //Page header
  1275.             $this->Header();
  1276.             //Restore line width
  1277.             if($this->LineWidth!=$lw{
  1278.                 $this->LineWidth=$lw;
  1279.                 $this->_out(sprintf('%.2f w',$lw*$this->k));
  1280.             }
  1281.             //Restore font
  1282.             if($family{
  1283.                 $this->SetFont($family,$style,$size);
  1284.             }
  1285.             //Restore colors
  1286.             if($this->DrawColor!=$dc{
  1287.                 $this->DrawColor=$dc;
  1288.                 $this->_out($dc);
  1289.             }
  1290.             if($this->FillColor!=$fc{
  1291.                 $this->FillColor=$fc;
  1292.                 $this->_out($fc);
  1293.             }
  1294.             $this->TextColor=$tc;
  1295.             $this->ColorFlag=$cf;
  1296.         }
  1297.         
  1298.         /**
  1299.           * Set header data.
  1300.          * @param string $ln header image logo
  1301.          * @param string $lw header image logo width in mm
  1302.          * @param string $ht string to print as title on document header
  1303.          * @param string $hs string to print on document header
  1304.         */
  1305.         public function setHeaderData($ln=""$lw=0$ht=""$hs=""{
  1306.             $this->header_logo $ln;
  1307.             $this->header_logo_width $lw;
  1308.             $this->header_title $ht;
  1309.             $this->header_string $hs;
  1310.         }
  1311.         
  1312.         /**
  1313.           * Set header margin.
  1314.          * (minimum distance between header and top page margin)
  1315.          * @param int $hm distance in millimeters
  1316.         */
  1317.         public function setHeaderMargin($hm=10{
  1318.             $this->header_margin $hm;
  1319.         }
  1320.         
  1321.         /**
  1322.           * Set footer margin.
  1323.          * (minimum distance between footer and bottom page margin)
  1324.          * @param int $fm distance in millimeters
  1325.         */
  1326.         public function setFooterMargin($fm=10{
  1327.             $this->footer_margin $fm;
  1328.         }
  1329.         
  1330.         /**
  1331.           * Set a flag to print page header.
  1332.          * @param boolean $val set to true to print the page header (default), false otherwise.
  1333.         */
  1334.         public function setPrintHeader($val=true{
  1335.             $this->print_header $val;
  1336.         }
  1337.         
  1338.         /**
  1339.           * Set a flag to print page footer.
  1340.          * @param boolean $value set to true to print the page footer (default), false otherwise.
  1341.         */
  1342.         public function setPrintFooter($val=true{
  1343.             $this->print_footer $val;
  1344.         }
  1345.         
  1346.         /**
  1347.           * This method is used to render the page header.
  1348.           * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  1349.          */
  1350.         public function Header({
  1351.             if ($this->print_header{
  1352.                 
  1353.                 if (!isset($this->original_lMargin)) {
  1354.                     $this->original_lMargin $this->lMargin;
  1355.                 }
  1356.                 if (!isset($this->original_rMargin)) {
  1357.                     $this->original_rMargin $this->rMargin;
  1358.                 }
  1359.                 
  1360.                 //set current position
  1361.                 $this->SetXY($this->original_lMargin$this->header_margin);
  1362.                 
  1363.                 if (($this->header_logoAND ($this->header_logo != K_BLANK_IMAGE)) {
  1364.                     $this->Image(K_PATH_IMAGES.$this->header_logo$this->original_lMargin$this->header_margin$this->header_logo_width);
  1365.                 }
  1366.                 else {
  1367.                     $this->img_rb_y = $this->GetY();
  1368.                 }
  1369.                 
  1370.                 $cell_height round((K_CELL_HEIGHT_RATIO $this->header_font[2]$this->k2);
  1371.                 
  1372.                 $header_x $this->original_lMargin ($this->header_logo_width 1.05)//set left margin for text data cell
  1373.                 
  1374.                 // header title
  1375.                 $this->SetFont($this->header_font[0]'B'$this->header_font[21);
  1376.                 $this->SetX($header_x);
  1377.                 $this->Cell($this->header_width$cell_height$this->header_title01'L')
  1378.                 
  1379.                 // header string
  1380.                 $this->SetFont($this->header_font[0]$this->header_font[1]$this->header_font[2]);
  1381.                 $this->SetX($header_x);
  1382.                 $this->MultiCell($this->header_width$cell_height$this->header_string0'L'0);
  1383.                 
  1384.                 // print an ending header line
  1385.                 if (empty($this->header_width)) {
  1386.                     //set style for cell border
  1387.                     $this->SetLineWidth(0.3);
  1388.                     $this->SetDrawColor(000);
  1389.                     $this->SetY(max($this->img_rb_y$this->GetY()));
  1390.                     $this->SetX($this->original_lMargin);
  1391.                     $this->Cell(00'''T'0'C')
  1392.                 }
  1393.                 
  1394.                 //restore position
  1395.                 $this->SetXY($this->original_lMargin$this->tMargin);
  1396.             }
  1397.         }
  1398.         
  1399.         /**
  1400.           * This method is used to render the page footer.
  1401.           * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  1402.          */
  1403.         public function Footer({
  1404.             if ($this->print_footer{
  1405.                 
  1406.                 if (!isset($this->original_lMargin)) {
  1407.                     $this->original_lMargin $this->lMargin;
  1408.                 }
  1409.                 if (!isset($this->original_rMargin)) {
  1410.                     $this->original_rMargin $this->rMargin;
  1411.                 }
  1412.                 
  1413.                 //set font
  1414.                 $this->SetFont($this->footer_font[0]$this->footer_font[1$this->footer_font[2]);
  1415.                 //set style for cell border
  1416.                 $line_width 0.3;
  1417.                 $this->SetLineWidth($line_width);
  1418.                 $this->SetDrawColor(000);
  1419.                 
  1420.                 $footer_height round((K_CELL_HEIGHT_RATIO $this->footer_font[2]$this->k2)//footer height
  1421.                 //get footer y position
  1422.                 $footer_y $this->h - $this->footer_margin $footer_height;
  1423.                 //set current position
  1424.                 $this->SetXY($this->original_lMargin$footer_y)
  1425.                 
  1426.                 //print document barcode
  1427.                 if ($this->barcode{
  1428.                     $this->Ln();
  1429.                     $barcode_width round(($this->w - $this->original_lMargin $this->original_rMargin))//max width
  1430.                     $this->writeBarcode($this->original_lMargin$footer_y $line_width$barcode_width$footer_height $line_width"C128B"falsefalse2$this->barcode);
  1431.                 }
  1432.                 
  1433.                 $this->SetXY($this->original_lMargin$footer_y)
  1434.                 
  1435.                 //Print page number
  1436.                 $this->Cell(0$footer_height$this->l['w_page']." ".$this->PageNo().' / {nb}''T'0'R')
  1437.             }
  1438.         }
  1439.         
  1440.         /**
  1441.         * Returns the current page number.
  1442.         * @return int page number
  1443.         * @since 1.0
  1444.         * @see AliasNbPages()
  1445.         */
  1446.         public function PageNo({
  1447.             //Get current page number
  1448.             return $this->page;
  1449.         }
  1450.  
  1451.         /**
  1452.         * 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.
  1453.         * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1454.         * @param int $g Green component (between 0 and 255)
  1455.         * @param int $b Blue component (between 0 and 255)
  1456.         * @since 1.3
  1457.         * @see SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  1458.         */
  1459.         public function SetDrawColor($r$g=-1$b=-1{
  1460.             //Set color for all stroking operations
  1461.             if(($r==and $g==and $b==0or $g==-1{
  1462.                 $this->DrawColor=sprintf('%.3f G',$r/255);
  1463.             }
  1464.             else {
  1465.                 $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
  1466.             }
  1467.             if($this->page>0{
  1468.                 $this->_out($this->DrawColor);
  1469.             }
  1470.         }
  1471.  
  1472.         /**
  1473.         * 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.
  1474.         * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1475.         * @param int $g Green component (between 0 and 255)
  1476.         * @param int $b Blue component (between 0 and 255)
  1477.         * @param boolean $storeprev if true stores the RGB array on $prevFillColor variable.
  1478.         * @since 1.3
  1479.         * @see SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  1480.         */
  1481.         public function SetFillColor($r$g=-1$b=-1$storeprev=false{
  1482.             //Set color for all filling operations
  1483.             if(($r==and $g==and $b==0or $g==-1{
  1484.                 $this->FillColor=sprintf('%.3f g',$r/255);
  1485.             }
  1486.             else {
  1487.                 $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  1488.             }
  1489.             $this->ColorFlag=($this->FillColor!=$this->TextColor);
  1490.             if($this->page>0{
  1491.                 $this->_out($this->FillColor);
  1492.             }
  1493.             if ($storeprev{
  1494.                 // store color as previous value
  1495.                 $this->prevFillColor array($r$g$b);
  1496.             }
  1497.         }
  1498.  
  1499.         /**
  1500.         * 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.
  1501.         * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1502.         * @param int $g Green component (between 0 and 255)
  1503.         * @param int $b Blue component (between 0 and 255)
  1504.         * @param boolean $storeprev if true stores the RGB array on $prevTextColor variable.
  1505.         * @since 1.3
  1506.         * @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  1507.         */
  1508.         public function SetTextColor($r$g=-1$b=-1$storeprev=false{
  1509.             //Set color for text
  1510.             if(($r==and $g==and $b==0or $g==-1{
  1511.                 $this->TextColor=sprintf('%.3f g',$r/255);
  1512.             }
  1513.             else {
  1514.                 $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  1515.             }
  1516.             $this->ColorFlag=($this->FillColor!=$this->TextColor);
  1517.             if ($storeprev{
  1518.                 // store color as previous value
  1519.                 $this->prevTextColor array($r$g$b);
  1520.             }
  1521.         }
  1522.  
  1523.         /**
  1524.         * Returns the length of a string in user unit. A font must be selected.<br>
  1525.         * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]
  1526.         * @param string $s The string whose length is to be computed
  1527.         * @return int 
  1528.         * @since 1.2
  1529.         */
  1530.         public function GetStringWidth($s{
  1531.             //Get width of a string in the current font
  1532.             $s = (string)$s;
  1533.             $cw &$this->CurrentFont['cw'];
  1534.             $w 0;
  1535.             if($this->isunicode{
  1536.                 $unicode $this->UTF8StringToArray($s);
  1537.                 foreach($unicode as $char{
  1538.                     if (isset($cw[$char])) {
  1539.                         $w+=$cw[$char];
  1540.                     elseif(isset($cw[ord($char)])) {
  1541.                         $w+=$cw[ord($char)];
  1542.                     elseif(isset($cw[chr($char)])) {
  1543.                         $w+=$cw[chr($char)];
  1544.                     elseif(isset($this->CurrentFont['desc']['MissingWidth'])) {
  1545.                         $w += $this->CurrentFont['desc']['MissingWidth']// set default size
  1546.                     else {
  1547.                         $w += 500;
  1548.                     }
  1549.                 }
  1550.             else {
  1551.                 $l strlen($s);
  1552.                 for($i=0$i<$l$i++{
  1553.                     if (isset($cw[$s{$i}])) {
  1554.                         $w += $cw[$s{$i}];
  1555.                     else if (isset($cw[ord($s{$i})])) {
  1556.                         $w += $cw[ord($s{$i})];
  1557.                     }
  1558.                 }
  1559.             }
  1560.             return ($w $this->FontSize / 1000);
  1561.         }
  1562.  
  1563.         /**
  1564.         * 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.
  1565.         * @param float $width The width.
  1566.         * @since 1.0
  1567.         * @see Line(), Rect(), Cell(), MultiCell()
  1568.         */
  1569.         public function SetLineWidth($width{
  1570.             //Set line width
  1571.             $this->LineWidth=$width;
  1572.             if($this->page>0{
  1573.                 $this->_out(sprintf('%.2f w',$width*$this->k));
  1574.             }
  1575.         }
  1576.  
  1577.         /**
  1578.         * Draws a line between two points.
  1579.         * @param float $x1 Abscissa of first point
  1580.         * @param float $y1 Ordinate of first point
  1581.         * @param float $x2 Abscissa of second point
  1582.         * @param float $y2 Ordinate of second point
  1583.         * @since 1.0
  1584.         * @see SetLineWidth(), SetDrawColor()
  1585.         */
  1586.         public function Line($x1$y1$x2$y2{
  1587.             //Draw a line
  1588.             $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));
  1589.         }
  1590.  
  1591.         /**
  1592.         * Outputs a rectangle. It can be drawn (border only), filled (with no border) or both.
  1593.         * @param float $x Abscissa of upper-left corner
  1594.         * @param float $y Ordinate of upper-left corner
  1595.         * @param float $w Width
  1596.         * @param float $h Height
  1597.         * @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>
  1598.         * @since 1.0
  1599.         * @see SetLineWidth(), SetDrawColor(), SetFillColor()
  1600.         */
  1601.         public function Rect($x$y$w$h$style=''{
  1602.             //Draw a rectangle
  1603.             if($style=='F'{
  1604.                 $op='f';
  1605.             }
  1606.             elseif($style=='FD' or $style=='DF'{
  1607.                 $op='B';
  1608.             }
  1609.             else {
  1610.                 $op='S';
  1611.             }
  1612.             $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
  1613.         }
  1614.  
  1615.         /**
  1616.         * 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.
  1617.         * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02].
  1618.         * <b>Example</b>:<br />
  1619.         * <pre>
  1620.         * $pdf->AddFont('Comic','I');
  1621.         * // is equivalent to:
  1622.         * $pdf->AddFont('Comic','I','comici.php');
  1623.         * </pre>
  1624.         * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  1625.         * @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>
  1626.         * @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no space.
  1627.         * @since 1.5
  1628.         * @see SetFont()
  1629.         */
  1630.         public function AddFont($family$style=''$file=''{
  1631.             if(empty($family)) {
  1632.                 return;
  1633.             }
  1634.  
  1635.             //Add a TrueType or Type1 font
  1636.             $family strtolower($family);
  1637.             if((!$this->isunicodeAND ($family == 'arial')) {
  1638.                 $family 'helvetica';
  1639.             }
  1640.  
  1641.             $style=strtoupper($style);
  1642.             $style=str_replace('U','',$style);
  1643.             if($style == 'IB'{
  1644.                 $style 'BI';
  1645.             }
  1646.  
  1647.             $fontkey $family.$style;
  1648.             // check if the font has been already added
  1649.             if(isset($this->fonts[$fontkey])) {
  1650.                 return;
  1651.             }
  1652.  
  1653.             if($file==''{
  1654.                 $file str_replace(' '''$family).strtolower($style).'.php';
  1655.             }
  1656.             if(!file_exists($this->_getfontpath().$file)) {
  1657.                 // try to load the basic file without styles
  1658.                 $file str_replace(' '''$family).'.php';
  1659.             }
  1660.  
  1661.             include($this->_getfontpath().$file);
  1662.  
  1663.             if(!isset($nameAND !isset($fpdf_charwidths)) {
  1664.                 $this->Error('Could not include font definition file');
  1665.             }
  1666.  
  1667.             $i count($this->fonts)+1;
  1668.  
  1669.             if($this->isunicode{
  1670.                 $this->fonts[$fontkeyarray('i'=>$i'type'=>$type'name'=>$name'desc'=>$desc'up'=>$up'ut'=>$ut'cw'=>$cw'enc'=>$enc'file'=>$file'ctg'=>$ctg);
  1671.                 $fpdf_charwidths[$fontkey$cw;
  1672.             else {
  1673.                 $this->fonts[$fontkey]=array('i'=>$i'type'=>'core''name'=>$this->CoreFonts[$fontkey]'up'=>-100'ut'=>50'cw'=>$fpdf_charwidths[$fontkey]);
  1674.             }
  1675.  
  1676.             if(isset($diffAND (!empty($diff))) {
  1677.                 //Search existing encodings
  1678.                 $d=0;
  1679.                 $nb=count($this->diffs);
  1680.                 for($i=1;$i<=$nb;$i++{
  1681.                     if($this->diffs[$i]==$diff{
  1682.                         $d=$i;
  1683.                         break;
  1684.                     }
  1685.                 }
  1686.                 if($d==0{
  1687.                     $d=$nb+1;
  1688.                     $this->diffs[$d]=$diff;
  1689.                 }
  1690.                 $this->fonts[$fontkey]['diff']=$d;
  1691.             }
  1692.             if(!empty($file)) {
  1693.                 if((strcasecmp($type,"TrueType"== 0OR (strcasecmp($type,"TrueTypeUnicode"== 0)) {
  1694.                     $this->FontFiles[$file]=array('length1'=>$originalsize);
  1695.                 }
  1696.                 else {
  1697.                     $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
  1698.                 }
  1699.             }
  1700.         }
  1701.  
  1702.         /**
  1703.         * 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.
  1704.         * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  1705.         * The method can be called before the first page is created and the font is retained from page to page.
  1706.         If you just wish to change the current font size, it is simpler to call SetFontSize().
  1707.         * 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 />
  1708.         * Example for the last case (note the trailing slash):<br />
  1709.         * <pre>
  1710.         * define('FPDF_FONTPATH','/home/www/font/');
  1711.         * require('tcpdf.php');
  1712.         *
  1713.         * //Times regular 12
  1714.         * $pdf->SetFont('Times');
  1715.         * //Arial bold 14
  1716.         * $pdf->SetFont('Arial','B',14);
  1717.         * //Removes bold
  1718.         * $pdf->SetFont('');
  1719.         * //Times bold, italic and underlined 14
  1720.         * $pdf->SetFont('Times','BIU');
  1721.         * </pre><br />
  1722.         * If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated.
  1723.         * @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.
  1724.         * @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
  1725.         * @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 document, the value taken is 12
  1726.         * @since 1.0
  1727.         * @see AddFont(), SetFontSize(), Cell(), MultiCell(), Write()
  1728.         */
  1729.         public function SetFont($family$style=''$size=0{
  1730.             // save previous values
  1731.             $this->prevFontFamily $this->FontFamily;
  1732.             $this->prevFontStyle $this->FontStyle;
  1733.  
  1734.             //Select a font; size given in points
  1735.             global $fpdf_charwidths;
  1736.  
  1737.             $family=strtolower($family);
  1738.             if($family==''{
  1739.                 $family=$this->FontFamily;
  1740.             }
  1741.             if((!$this->isunicodeAND ($family == 'arial')) {
  1742.                 $family 'helvetica';
  1743.             }
  1744.             elseif(($family=="symbol"OR ($family=="zapfdingbats")) {
  1745.                 $style='';
  1746.             }
  1747.             $style=strtoupper($style);
  1748.  
  1749.             if(strpos($style,'U')!==false{
  1750.                 $this->underline=true;
  1751.                 $style=str_replace('U','',$style);
  1752.             }
  1753.             else {
  1754.                 $this->underline=false;
  1755.             }
  1756.             if($style=='IB'{
  1757.                 $style='BI';
  1758.             }
  1759.             if($size==0{
  1760.                 $size=$this->FontSizePt;
  1761.             }
  1762.  
  1763.             // try to add font (if not already added)
  1764.             if($this->isunicode{
  1765.                 $this->AddFont($family$style);
  1766.             }
  1767.             
  1768.             //Test if font is already selected
  1769.             if(($this->FontFamily == $familyAND ($this->FontStyle == $styleAND ($this->FontSizePt == $size)) {
  1770.                 return;
  1771.             }
  1772.             
  1773.             $fontkey $family.$style;
  1774.             //if(!isset($this->fonts[$fontkey]) AND isset($this->fonts[$family])) {
  1775.             //    $style='';
  1776.             //}
  1777.  
  1778.             //Test if used for the first time
  1779.             if(!isset($this->fonts[$fontkey])) {
  1780.                 //Check if one of the standard fonts
  1781.                 if(isset($this->CoreFonts[$fontkey])) {
  1782.                     if(!isset($fpdf_charwidths[$fontkey])) {
  1783.                         //Load metric file
  1784.                         $file $family;
  1785.                         if(($family!='symbol'AND ($family!='zapfdingbats')) {
  1786.                             $file .= strtolower($style);
  1787.                         }
  1788.                         if(!file_exists($this->_getfontpath().$file.'.php')) {
  1789.                             // try to load the basic file without styles
  1790.                             $file $family;
  1791.                             $fontkey $family;
  1792.                         }
  1793.                         include($this->_getfontpath().$file.'.php');
  1794.                         if (($this->isunicode AND !isset($ctg)) OR ((!$this->isunicodeAND (!isset($fpdf_charwidths[$fontkey]))) ) {
  1795.                             $this->Error("Could not include font metric file [".$fontkey."]: ".$this->_getfontpath().$file.".php");
  1796.                         }
  1797.                     }
  1798.                     $i count($this->fonts1;
  1799.  
  1800.                     if($this->isunicode{
  1801.                         $this->fonts[$fontkeyarray('i'=>$i'type'=>$type'name'=>$name'desc'=>$desc'up'=>$up'ut'=>$ut'cw'=>$cw'enc'=>$enc'file'=>$file'ctg'=>$ctg);
  1802.                         $fpdf_charwidths[$fontkey$cw;
  1803.                     else {
  1804.                         $this->fonts[$fontkey]=array('i'=>$i'type'=>'core''name'=>$this->CoreFonts[$fontkey]'up'=>-100'ut'=>50'cw'=>$fpdf_charwidths[$fontkey]);
  1805.                     }
  1806.                 }
  1807.                 else {
  1808.                     $this->Error('Undefined font: '.$family.' '.$style);
  1809.                 }
  1810.             }
  1811.             //Select it
  1812.             $this->FontFamily = $family;
  1813.             $this->FontStyle = $style;
  1814.             $this->FontSizePt = $size;
  1815.             $this->FontSize = $size $this->k;
  1816.             $this->CurrentFont = &$this->fonts[$fontkey];
  1817.             if($this->page>0{
  1818.                 $this->_out(sprintf('BT /F%d %.2f Tf ET'$this->CurrentFont['i']$this->FontSizePt));
  1819.             }
  1820.         }
  1821.  
  1822.         /**
  1823.         * Defines the size of the current font.
  1824.         * @param float $size The size (in points)
  1825.         * @since 1.0
  1826.         * @see SetFont()
  1827.         */
  1828.         public function SetFontSize($size{
  1829.             //Set font size in points
  1830.             if($this->FontSizePt==$size{
  1831.                 return;
  1832.             }
  1833.             $this->FontSizePt = $size;
  1834.             $this->FontSize = $size $this->k;
  1835.             if($this->page > 0{
  1836.                 $this->_out(sprintf('BT /F%d %.2f Tf ET'$this->CurrentFont['i']$this->FontSizePt));
  1837.             }
  1838.         }
  1839.  
  1840.         /**
  1841.         * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
  1842.         * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  1843.         * @since 1.5
  1844.         * @see Cell(), Write(), Image(), Link(), SetLink()
  1845.         */
  1846.         public function AddLink({
  1847.             //Create a new internal link
  1848.             $n=count($this->links)+1;
  1849.             $this->links[$n]=array(0,0);
  1850.             return $n;
  1851.         }
  1852.  
  1853.         /**
  1854.         * Defines the page and position a link points to
  1855.         * @param int $link The link identifier returned by AddLink()
  1856.         * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  1857.         * @param int $page Number of target page; -1 indicates the current page. This is the default value
  1858.         * @since 1.5
  1859.         * @see AddLink()
  1860.         */
  1861.         public function SetLink($link$y=0$page=-1{
  1862.             //Set destination of internal link
  1863.             if($y==-1{
  1864.                 $y=$this->y;
  1865.             }
  1866.             if($page==-1{
  1867.                 $page=$this->page;
  1868.             }
  1869.             $this->links[$link]=array($page,$y);
  1870.         }
  1871.  
  1872.         /**
  1873.         * Puts a link on a rectangular area of the page. Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.
  1874.         * @param float $x Abscissa of the upper-left corner of the rectangle
  1875.         * @param float $y Ordinate of the upper-left corner of the rectangle
  1876.         * @param float $w Width of the rectangle
  1877.         * @param float $h Height of the rectangle
  1878.         * @param mixed $link URL or identifier returned by AddLink()
  1879.         * @since 1.5
  1880.         * @see AddLink(), Cell(), Write(), Image()
  1881.         */
  1882.         public function Link($x$y$w$h$link{
  1883.             //Put a link on the page
  1884.             $this->PageLinks[$this->page][array($x $this->k$this->hPt - $y $this->k$w $this->k$h*$this->k$link);
  1885.         }
  1886.  
  1887.         /**
  1888.         * Prints a character string. The origin is on the left of the first charcter, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use Cell(), MultiCell() or Write() which are the standard methods to print text.
  1889.         * @param float $x Abscissa of the origin
  1890.         * @param float $y Ordinate of the origin
  1891.         * @param string $txt String to print
  1892.         * @since 1.0
  1893.         * @see SetFont(), SetTextColor(), Cell(), MultiCell(), Write()
  1894.         */
  1895.         public function Text($x$y$txt{
  1896.             //Output a string
  1897.             $s=sprintf('BT %.2f %.2f Td (%s) Tj ET'$x $this->k($this->h-$y$this->k$this->_escapetext($txt));
  1898.             if($this->underline AND ($txt!='')) {
  1899.                 $s .= ' '.$this->_dounderline($x,$y,$txt);
  1900.             }
  1901.             if($this->ColorFlag{
  1902.                 $s='q '.$this->TextColor.' '.$s.' Q';
  1903.             }
  1904.             $this->_out($s);
  1905.         }
  1906.  
  1907.         /**
  1908.         * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  1909.         * This method is called automatically and should not be called directly by the application.<br />
  1910.         * <b>Example:</b><br />
  1911.         * The method is overriden in an inherited class in order to obtain a 3 column layout:<br />
  1912.         * <pre>
  1913.         * class PDF extends TCPDF {
  1914.         *     var $col=0;
  1915.         *
  1916.         *     public function SetCol($col) {
  1917.         *         //Move position to a column
  1918.         *         $this->col=$col;
  1919.         *         $x=10+$col*65;
  1920.         *         $this->SetLeftMargin($x);
  1921.         *         $this->SetX($x);
  1922.         *     }
  1923.         *
  1924.         *     public function AcceptPageBreak() {
  1925.         *         if($this->col<2) {
  1926.         *             //Go to next column
  1927.         *             $this->SetCol($this->col+1);
  1928.         *             $this->SetY(10);
  1929.         *             return false;
  1930.         *         }
  1931.         *         else {
  1932.         *             //Go back to first column and issue page break
  1933.         *             $this->SetCol(0);
  1934.         *             return true;
  1935.         *         }
  1936.         *     }
  1937.         * }
  1938.         *
  1939.         * $pdf=new PDF();
  1940.         * $pdf->Open();
  1941.         * $pdf->AddPage();
  1942.         * $pdf->SetFont('Arial','',12);
  1943.         * for($i=1;$i<=300;$i++) {
  1944.         *     $pdf->Cell(0,5,"Line $i",0,1);
  1945.         * }
  1946.         * $pdf->Output();
  1947.         * </pre>
  1948.         * @return boolean 
  1949.         * @since 1.4
  1950.         * @see SetAutoPageBreak()
  1951.         */
  1952.         public function AcceptPageBreak({
  1953.             //Accept automatic page break or not
  1954.             return $this->AutoPageBreak;
  1955.         }
  1956.  
  1957.         /**
  1958.         * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
  1959.         * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  1960.         * @param float $w Cell width. If 0, the cell extends up to the right margin.
  1961.         * @param float $h Cell height. Default value: 0.
  1962.         * @param string $txt String to print. Default value: empty string.
  1963.         * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  1964.         * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  1965.         Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  1966.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li></ul>
  1967.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  1968.         * @param mixed $link URL or identifier returned by AddLink().
  1969.         * @since 1.0
  1970.         * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  1971.         */
  1972.         public function Cell($w$h=0$txt=''$border=0$ln=0$align=''$fill=0$link=''{
  1973.             //Output a cell
  1974.             $k=$this->k;
  1975.             if(($this->y + $h$this->PageBreakTrigger AND empty($this->InFooterAND $this->AcceptPageBreak()) {
  1976.                 //Automatic page break
  1977.                 $x $this->x;
  1978.                 $ws $this->ws;
  1979.                 if($ws 0{
  1980.                     $this->ws = 0;
  1981.                     $this->_out('0 Tw');
  1982.                 }
  1983.                 $this->AddPage($this->CurOrientation);
  1984.                 $this->x = $x;
  1985.                 if($ws 0{
  1986.                     $this->ws = $ws;
  1987.                     $this->_out(sprintf('%.3f Tw',$ws $k));
  1988.                 }
  1989.             }
  1990.             if($w == 0{
  1991.                 $w $this->w - $this->rMargin - $this->x;
  1992.             }
  1993.             $s '';
  1994.             if(($fill == 1OR ($border == 1)) {
  1995.                 if($fill == 1{
  1996.                     $op ($border == 1'B' 'f';
  1997.                 }
  1998.                 else {
  1999.                     $op 'S';
  2000.                 }
  2001.                 $s sprintf('%.2f %.2f %.2f %.2f re %s '$this->x * $k($this->h - $this->y$k$w $k-$h $k$op);
  2002.             }
  2003.             if(is_string($border)) {
  2004.                 $x=$this->x;
  2005.                 $y=$this->y;
  2006.                 if(strpos($border,'L')!==false{
  2007.                     $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
  2008.                 }
  2009.                 if(strpos($border,'T')!==false{
  2010.                     $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
  2011.                 }
  2012.                 if(strpos($border,'R')!==false{
  2013.                     $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
  2014.                 }
  2015.                 if(strpos($border,'B')!==false{
  2016.                     $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
  2017.                 }
  2018.             }
  2019.             if($txt != ''{
  2020.                 $width $this->GetStringWidth($txt);
  2021.                 if($align == 'R'{
  2022.                     $dx $w $this->cMargin - $width;
  2023.                 }
  2024.                 elseif($align=='C'{
  2025.                     $dx ($w $width)/2;
  2026.                 }
  2027.                 else {
  2028.                     $dx $this->cMargin;
  2029.                 }
  2030.                 if($this->ColorFlag{
  2031.                     $s .= 'q '.$this->TextColor.' ';
  2032.                 }
  2033.                 $txt2 $this->_escapetext($txt);
  2034.                 $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET'($this->x + $dx$k($this->h - ($this->y + 0.5 $h 0.3 $this->FontSize)) $k$txt2);
  2035.                 if($this->underline{
  2036.                     $s.=' '.$this->_dounderline($this->x + $dx$this->y + 0.5 $h 0.3 $this->FontSize$txt);
  2037.                 }
  2038.                 if($this->ColorFlag{
  2039.                     $s.=' Q';
  2040.                 }
  2041.                 if($link{
  2042.                     $this->Link($this->x + $dx$this->y + 0.5 $h 0.5 $this->FontSize$width$this->FontSize$link);
  2043.                 }
  2044.             }
  2045.             if($s{
  2046.                 $this->_out($s);
  2047.             }
  2048.             $this->lasth = $h;
  2049.             if($ln>0{
  2050.                 //Go to next line
  2051.                 $this->y += $h;
  2052.                 if($ln == 1{
  2053.                     $this->x = $this->lMargin;
  2054.                 }
  2055.             }
  2056.             else {
  2057.                 $this->x += $w;
  2058.             }
  2059.         }
  2060.  
  2061.         /**
  2062.         * This method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br />
  2063.         * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  2064.         * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  2065.         * @param float $h Height of cells.
  2066.         * @param string $txt String to print
  2067.         * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  2068.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value)</li></ul>
  2069.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  2070.         * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
  2071.         * @since 1.3
  2072.         * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  2073.         */
  2074.         public function MultiCell($w$h$txt$border=0$align='J'$fill=0$ln=1{
  2075.             
  2076.             // save current position
  2077.             $prevx $this->x;
  2078.             $prevy $this->y;
  2079.              
  2080.             //Output text with automatic or explicit line breaks
  2081.             $cw &$this->CurrentFont['cw'];
  2082.  
  2083.             if($w == 0{
  2084.                 $w $this->w - $this->rMargin - $this->x;
  2085.             }
  2086.  
  2087.             $wmax ($w $this->cMargin);
  2088.  
  2089.             $s str_replace("\r"''$txt)// remove carriage returns
  2090.             $nb strlen($s);
  2091.  
  2092.             $b=0;
  2093.             if($border{
  2094.                 if($border==1{
  2095.                     $border='LTRB';
  2096.                     $b='LRT';
  2097.                     $b2='LR';
  2098.                 }
  2099.                 else {
  2100.                     $b2='';
  2101.                     if(strpos($border,'L')!==false{
  2102.                         $b2.='L';
  2103.                     }
  2104.                     if(strpos($border,'R')!==false{
  2105.                         $b2.='R';
  2106.                     }
  2107.                     $b=(strpos($border,'T')!==false$b2.'T' $b2;
  2108.                 }
  2109.             }
  2110.             $sep=-1;
  2111.             $i=0;
  2112.             $j=0;
  2113.             $l=0;
  2114.             $ns=0;
  2115.             $nl=1;
  2116.             while($i<$nb{
  2117.                 //Get next character
  2118.                 $c $s{$i};
  2119.                 if(preg_match("/[\n]/u"$c)) {
  2120.                     //Explicit line break
  2121.                     if($this->ws > 0{
  2122.                         $this->ws = 0;
  2123.                         $this->_out('0 Tw');
  2124.                     }
  2125.                     $this->Cell($w$hsubstr($s$j$i-$j)$b2$align$fill);
  2126.                     $i++;
  2127.                     $sep=-1;
  2128.                     $j=$i;
  2129.                     $l=0;
  2130.                     $ns=0;
  2131.                     $nl++;
  2132.                     if($border and $nl==2{
  2133.                         $b $b2;
  2134.                     }
  2135.                     continue;
  2136.                 }
  2137.                 if(preg_match("/[ ]/u"$c)) {
  2138.                     $sep $i;
  2139.                     $ls $l;
  2140.                     $ns++;
  2141.                 }
  2142.  
  2143.                 $l $this->GetStringWidth(substr($s$j$i-$j));
  2144.  
  2145.                 if($l $wmax{
  2146.                     //Automatic line break
  2147.                     if($sep == -1{
  2148.                         if($i == $j{
  2149.                             $i++;
  2150.                         }
  2151.                         if($this->ws > 0{
  2152.                             $this->ws = 0;
  2153.                             $this->_out('0 Tw');
  2154.                         }
  2155.                         $this->Cell($w$hsubstr($s$j$i-$j)$b2$align$fill);
  2156.                     }
  2157.                     else {
  2158.                         if($align=='J'{
  2159.                             $this->ws = ($ns>1($wmax-$ls)/($ns-10;
  2160.                             $this->_out(sprintf('%.3f Tw'$this->ws * $this->k));
  2161.                         }
  2162.                         $this->Cell($w$hsubstr($s$j$sep-$j)$b2$align$fill);
  2163.                         $i $sep 1;
  2164.                     }
  2165.                     $sep=-1;
  2166.                     $j=$i;
  2167.                     $l=0;
  2168.                     $ns=0;
  2169.                     $nl++;
  2170.                     if($border AND ($nl==2)) {
  2171.                         $b=$b2;
  2172.                     }
  2173.                 }
  2174.                 else {
  2175.                     $i++;
  2176.                 }
  2177.             }
  2178.             //Last chunk
  2179.             if($this->ws>0{
  2180.                 $this->ws=0;
  2181.                 $this->_out('0 Tw');
  2182.             }
  2183.             if($border and is_int(strpos($border,'B'))) {
  2184.                 $b.='B';
  2185.             }
  2186.             $this->Cell($w$hsubstr($s$j$i-$j)$b2$align$fill);
  2187.             
  2188.             // move cursor to specified position
  2189.             // since: 2007-03-03
  2190.              if($ln == 1{
  2191.                 // go to the beginning of the next line
  2192.                 $this->x = $this->lMargin;
  2193.             elseif($ln == 0{
  2194.                 // go to the top-right of the cell
  2195.                 $this->y = $prevy;
  2196.                 $this->x = $prevx $w;
  2197.             elseif($ln == 2{
  2198.                 // go to the bottom-left of the cell
  2199.                 $this->x = $prevx;
  2200.             }
  2201.         }
  2202.  
  2203.         /**
  2204.         * This method prints text from the current position. When the right margin is reached (or the \n character is met) a line break occurs and text continues from the left margin. Upon method exit, the current position is left just at the end of the text. It is possible to put a link on the text.<br />
  2205.         * <b>Example:</b><br />
  2206.         * <pre>
  2207.         * //Begin with regular font
  2208.         * $pdf->SetFont('Arial','',14);
  2209.         * $pdf->Write(5,'Visit ');
  2210.         * //Then put a blue underlined link
  2211.         * $pdf->SetTextColor(0,0,255);
  2212.         * $pdf->SetFont('','U');
  2213.         * $pdf->Write(5,'www.tecnick.com','http://www.tecnick.com');
  2214.         * </pre>
  2215.         * @param float $h Line height
  2216.         * @param string $txt String to print
  2217.         * @param mixed $link URL or identifier returned by AddLink()
  2218.         * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  2219.         * @since 1.5
  2220.         * @see SetFont(), SetTextColor(), AddLink(), MultiCell(), SetAutoPageBreak()
  2221.         */
  2222.         public function Write($h$txt$link=''$fill=0{
  2223.  
  2224.             //Output text in flowing mode
  2225.             $cw &$this->CurrentFont['cw'];
  2226.             $w $this->w - $this->rMargin - $this->x;
  2227.             $wmax ($w $this->cMargin);
  2228.  
  2229.             $s str_replace("\r"''$txt);
  2230.             $nb strlen($s);
  2231.  
  2232.             // handle single space character
  2233.             if(($nb==1AND preg_match("/[ ]/u"$s)) {
  2234.                 $this->x += $this->GetStringWidth($s);
  2235.                 return;
  2236.             }
  2237.  
  2238.             $sep=-1;
  2239.             $i=0;
  2240.             $j=0;
  2241.             $l=0;
  2242.             $nl=1;
  2243.             while($i<$nb{
  2244.                 //Get next character
  2245.                 $c=$s{$i};
  2246.                 if(preg_match("/[\n]/u"$c)) {
  2247.                     //Explicit line break
  2248.                     $this->Cell($w$hsubstr($s$j$i-$j)02''$fill$link);
  2249.                     $i++;
  2250.                     $sep = -1;
  2251.                     $j $i;
  2252.                     $l 0;
  2253.                     if($nl == 1{
  2254.                         $this->x = $this->lMargin;
  2255.                         $w $this->w - $this->rMargin - $this->x;
  2256.                         $wmax ($w $this->cMargin);
  2257.                     }
  2258.                     $nl++;
  2259.                     continue;
  2260.                 }
  2261.                 if(preg_match("/[ ]/u"$c)) {
  2262.                     $sep$i;
  2263.                 }
  2264.  
  2265.                 $l $this->GetStringWidth(substr($s$j$i-$j));
  2266.  
  2267.                 if($l $wmax{
  2268.                     //Automatic line break (word wrapping)
  2269.                     if($sep == -1{
  2270.                         if($this->x > $this->lMargin{
  2271.                             //Move to next line
  2272.                             $this->x = $this->lMargin;
  2273.                             $this->y += $h;
  2274.                             $w=$this->w - $this->rMargin - $this->x;
  2275.                             $wmax=($w $this->cMargin);
  2276.                             $i++;
  2277.                             $nl++;
  2278.                             continue;
  2279.                         }
  2280.                         if($i==$j{
  2281.                             $i++;
  2282.                         }
  2283.                         $this->Cell($w$hsubstr($s$j$i-$j)02''$fill$link);
  2284.                     }
  2285.                     else {
  2286.                         $this->Cell($w$hsubstr($s$j$sep-$j)02''$fill$link);
  2287.                         $i=$sep+1;
  2288.                     }
  2289.                     $sep = -1;
  2290.                     $j $i;
  2291.                     $l 0;
  2292.                     if($nl==1{
  2293.                         $this->x = $this->lMargin;
  2294.                         $w $this->w - $this->rMargin - $this->x;
  2295.                         $wmax ($w $this->cMargin);
  2296.                     }
  2297.                     $nl++;
  2298.                 }
  2299.                 else {
  2300.                     $i++;
  2301.                 }
  2302.             }
  2303.             
  2304.             //Last chunk
  2305.             if($i!=$j{
  2306.                 $this->Cell($this->GetStringWidth(substr($s$j))$hsubstr($s$j)00''$fill$link);
  2307.             }
  2308.         }
  2309.  
  2310.         /**
  2311.         * Puts an image in the page. The upper-left corner must be given. The dimensions can be specified in different ways:<ul><li>explicit width and height (expressed in user unit)</li><li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li><li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  2312.         * Supported formats are JPEG and PNG.
  2313.         * For JPEG, all flavors are allowed:<ul><li>gray scales</li><li>true colors (24 bits)</li><li>CMYK (32 bits)</li></ul>
  2314.         * For PNG, are allowed:<ul><li>gray scales on at most 8 bits (256 levels)</li><li>indexed colors</li><li>true colors (24 bits)</li></ul>
  2315.         * but are not supported:<ul><li>Interlacing</li><li>Alpha channel</li></ul>
  2316.         * If a transparent color is defined, it will be taken into account (but will be only interpreted by Acrobat 4 and above).<br />
  2317.         * The format can be specified explicitly or inferred from the file extension.<br />
  2318.         * It is possible to put a link on the image.<br />
  2319.         * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  2320.         * @param string $file Name of the file containing the image.
  2321.         * @param float $x Abscissa of the upper-left corner.
  2322.         * @param float $y Ordinate of the upper-left corner.
  2323.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  2324.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  2325.         * @param string $type Image format. Possible values are (case insensitive): JPG, JPEG, PNG. If not specified, the type is inferred from the file extension.
  2326.         * @param mixed $link URL or identifier returned by AddLink().
  2327.         * @since 1.1
  2328.         * @see AddLink()
  2329.         */
  2330.         public function Image($file$x$y$w=0$h=0$type=''$link=''{
  2331.             //Put an image on the page
  2332.             if(!isset($this->images[$file])) {
  2333.                 //First use of image, get info
  2334.                 if($type == ''{
  2335.                     $pos strrpos($file,'.');
  2336.                     if(empty($pos)) {
  2337.                         $this->Error('Image file has no extension and no type was specified: '.$file);
  2338.                     }
  2339.                     $type substr($file$pos+1);
  2340.                 }
  2341.                 $type strtolower($type);
  2342.                 $mqr get_magic_quotes_runtime();
  2343.                 set_magic_quotes_runtime(0);
  2344.                 if($type == 'jpg' or $type == 'jpeg'{
  2345.                     $info=$this->_parsejpg($file);
  2346.                 }
  2347.                 elseif($type == 'png'{
  2348.                     $info=$this->_parsepng($file);
  2349.                 }
  2350.                 else {
  2351.                     //Allow for additional formats
  2352.                     $mtd='_parse'.$type;
  2353.                     if(!method_exists($this,$mtd)) {
  2354.                         $this->Error('Unsupported image type: '.$type);
  2355.                     }
  2356.                     $info=$this->$mtd($file);
  2357.                 }
  2358.                 set_magic_quotes_runtime($mqr);
  2359.                 $info['i']=count($this->images)+1;
  2360.                 $this->images[$file]=$info;
  2361.             }
  2362.             else {
  2363.                 $info=$this->images[$file];
  2364.             }
  2365.             //Automatic width and height calculation if needed
  2366.             if(($w == 0and ($h == 0)) {
  2367.                 //Put image at 72 dpi
  2368.                 // 2004-06-14 :: Nicola Asuni, scale factor where added
  2369.                 $w $info['w'($this->imgscale * $this->k);
  2370.                 $h $info['h'($this->imgscale * $this->k);
  2371.             }
  2372.             if($w == 0{
  2373.                 $w $h $info['w'$info['h'];
  2374.             }
  2375.             if($h == 0{
  2376.                 $h $w $info['h'$info['w'];
  2377.             }
  2378.             $this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q'$w*$this->k$h*$this->k$x*$this->k($this->h-($y+$h))*$this->k$info['i']));
  2379.             if($link{
  2380.                 $this->Link($x$y$w$h$link);
  2381.             }
  2382.  
  2383.             //2002-07-31 - Nicola Asuni
  2384.             // set right-bottom corner coordinates
  2385.             $this->img_rb_x = $x $w;
  2386.             $this->img_rb_y = $y $h;
  2387.         }
  2388.  
  2389.         /**
  2390.         * Performs a line break. The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  2391.         * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  2392.         * @since 1.0
  2393.         * @see Cell()
  2394.         */
  2395.         public function Ln($h=''{
  2396.             //Line feed; default value is last cell height
  2397.             $this->x=$this->lMargin;
  2398.             if(is_string($h)) {
  2399.                 $this->y+=$this->lasth;
  2400.             }
  2401.             else {
  2402.                 $this->y+=$h;
  2403.             }
  2404.         }
  2405.  
  2406.         /**
  2407.         * Returns the abscissa of the current position.
  2408.         * @return float 
  2409.         * @since 1.2
  2410.         * @see SetX(), GetY(), SetY()
  2411.         */
  2412.         public function GetX({
  2413.             //Get x position
  2414.             return $this->x;
  2415.         }
  2416.  
  2417.         /**
  2418.         * Defines the abscissa of the current position. If the passed value is negative, it is relative to the right of the page.
  2419.         * @param float $x The value of the abscissa.
  2420.         * @since 1.2
  2421.         * @see GetX(), GetY(), SetY(), SetXY()
  2422.         */
  2423.         public function SetX($x{
  2424.             //Set x position
  2425.             if($x>=0{
  2426.                 $this->x=$x;
  2427.             }
  2428.             else {
  2429.                 $this->x=$this->w+$x;
  2430.             }
  2431.         }
  2432.  
  2433.         /**
  2434.         * Returns the ordinate of the current position.
  2435.         * @return float 
  2436.         * @since 1.0
  2437.         * @see SetY(), GetX(), SetX()
  2438.         */
  2439.         public function GetY({
  2440.             //Get y position
  2441.             return $this->y;
  2442.         }
  2443.  
  2444.         /**
  2445.         * Moves the current abscissa back to the left margin and sets the ordinate. If the passed value is negative, it is relative to the bottom of the page.
  2446.         * @param float $y The value of the ordinate.
  2447.         * @since 1.0
  2448.         * @see GetX(), GetY(), SetY(), SetXY()
  2449.         */
  2450.         public function SetY($y{
  2451.             //Set y position and reset x
  2452.             $this->x=$this->lMargin;
  2453.             if($y>=0{
  2454.                 $this->y=$y;
  2455.             }
  2456.             else {
  2457.                 $this->y=$this->h+$y;
  2458.             }
  2459.         }
  2460.  
  2461.         /**
  2462.         * Defines the abscissa and ordinate of the current position. If the passed values are negative, they are relative respectively to the right and bottom of the page.
  2463.         * @param float $x The value of the abscissa
  2464.         * @param float $y The value of the ordinate
  2465.         * @since 1.2
  2466.         * @see SetX(), SetY()
  2467.         */
  2468.         public function SetXY($x$y{
  2469.             //Set x and y positions
  2470.             $this->SetY($y);
  2471.             $this->SetX($x);
  2472.         }
  2473.  
  2474.         /**
  2475.         * Send the document to a given destination: string, local file or browser. In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  2476.         * The method first calls Close() if necessary to terminate the document.
  2477.         * @param string $name The name of the file. If not given, the document will be sent to the browser (destination I) with the name doc.pdf.
  2478.         * @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser. The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local file with the name given by name.</li><li>S: return the document as a string. name is ignored.</li></ul>If the parameter is not specified but a name is given, destination is F. If no parameter is specified at all, destination is I.<br />Note: for compatibility with previous versions, a boolean value is also accepted (false for F and true for D).
  2479.         * @since 1.0
  2480.         * @see Close()
  2481.         */
  2482.         public function Output($name='',$dest=''{
  2483.             //Output PDF to some destination
  2484.             //Finish document if necessary
  2485.             if($this->state < 3{
  2486.                 $this->Close();
  2487.             }
  2488.             //Normalize parameters
  2489.             if(is_bool($dest)) {
  2490.                 $dest=$dest 'D' 'F';
  2491.             }
  2492.             $dest=strtoupper($dest);
  2493.             if($dest==''{
  2494.                 if($name==''{
  2495.                     $name='doc.pdf';
  2496.                     $dest='I';
  2497.                 else {
  2498.                     $dest='F';
  2499.                 }
  2500.             }
  2501.             switch($dest{
  2502.                 case 'I'{
  2503.                     //Send to standard output
  2504.                     if(ob_get_contents()) {
  2505.                         $this->Error('Some data has already been output, can\'t send PDF file');
  2506.                     }
  2507.                     if(php_sapi_name()!='cli'{
  2508.                         //We send to a browser
  2509.                         header('Content-Type: application/pdf');
  2510.                         if(headers_sent()) {
  2511.                             $this->Error('Some data has already been output to browser, can\'t send PDF file');
  2512.                         }
  2513.                         header('Content-Length: '.strlen($this->buffer));
  2514.                         header('Content-disposition: inline; filename="'.$name.'"');
  2515.                     }
  2516.                     echo $this->buffer;
  2517.                     break;
  2518.                 }
  2519.                 case 'D'{
  2520.                     //Download file
  2521.                     if(ob_get_contents()) {
  2522.                         $this->Error('Some data has already been output, can\'t send PDF file');
  2523.                     }
  2524.                     if(isset($_SERVER['HTTP_USER_AGENT']&& strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) {
  2525.                         header('Content-Type: application/force-download');
  2526.                     else {
  2527.                         header('Content-Type: application/octet-stream');
  2528.                     }
  2529.                     if(headers_sent()) {
  2530.                         $this->Error('Some data has already been output to browser, can\'t send PDF file');
  2531.                     }
  2532.                     header('Content-Length: '.strlen($this->buffer));
  2533.                     header('Content-disposition: attachment; filename="'.$name.'"');
  2534.                     echo $this->buffer;
  2535.                     break;
  2536.                 }
  2537.                 case 'F'{
  2538.                     //Save to local file
  2539.                     $f=fopen($name,'wb');
  2540.                     if(!$f{
  2541.                         $this->Error('Unable to create output file: '.$name);
  2542.                     }
  2543.                     fwrite($f,$this->buffer,strlen($this->buffer));
  2544.                     fclose($f);
  2545.                     break;
  2546.                 }
  2547.                 case 'S'{
  2548.                     //Return as a string
  2549.                     return $this->buffer;
  2550.                 }
  2551.                 default{
  2552.                     $this->Error('Incorrect output destination: '.$dest);
  2553.                 }
  2554.             }
  2555.             return '';
  2556.         }
  2557.  
  2558.         // Protected methods
  2559.  
  2560.         /**
  2561.         * Check for locale-related bug
  2562.         * @access protected
  2563.         */
  2564.         protected function _dochecks({
  2565.             //Check for locale-related bug
  2566.             if(1.1==1{
  2567.                 $this->Error('Don\'t alter the locale before including class file');
  2568.             }
  2569.             //Check for decimal separator
  2570.             if(sprintf('%.1f',1.0)!='1.0'{
  2571.                 setlocale(LC_NUMERIC,'C');
  2572.             }
  2573.         }
  2574.  
  2575.         /**
  2576.         * Return fonts path
  2577.         * @access protected
  2578.         */
  2579.         protected function _getfontpath({
  2580.             if(!defined('FPDF_FONTPATH'AND is_dir(dirname(__FILE__).'/font')) {
  2581.                 define('FPDF_FONTPATH'dirname(__FILE__).'/font/');
  2582.             }
  2583.             return defined('FPDF_FONTPATH'FPDF_FONTPATH '';
  2584.         }
  2585.  
  2586.         /**
  2587.         * Start document
  2588.         * @access protected
  2589.         */
  2590.         protected function _begindoc({
  2591.             //Start document
  2592.             $this->state=1;
  2593.             $this->_out('%PDF-1.3');
  2594.         }
  2595.  
  2596.         /**
  2597.         * _putpages
  2598.         * @access protected
  2599.         */
  2600.         protected function _putpages({
  2601.             $nb $this->page;
  2602.             if(!empty($this->AliasNbPages)) {
  2603.                 $nbstr $this->UTF8ToUTF16BE($nbfalse);
  2604.                 //Replace number of pages
  2605.                 for($n=1;$n<=$nb;$n++{
  2606.                     $this->pages[$n]=str_replace($this->AliasNbPages$nbstr$this->pages[$n]);
  2607.                 }
  2608.             }
  2609.             if($this->DefOrientation=='P'{
  2610.                 $wPt=$this->fwPt;
  2611.                 $hPt=$this->fhPt;
  2612.             }
  2613.             else {
  2614.                 $wPt=$this->fhPt;
  2615.                 $hPt=$this->fwPt;
  2616.             }
  2617.             $filter=($this->compress'/Filter /FlateDecode ' '';
  2618.             for($n=1;$n<=$nb;$n++{
  2619.                 //Page
  2620.                 $this->_newobj();
  2621.                 $this->_out('<</Type /Page');
  2622.                 $this->_out('/Parent 1 0 R');
  2623.                 if(isset($this->OrientationChanges[$n])) {
  2624.                     $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt));
  2625.                 }
  2626.                 $this->_out('/Resources 2 0 R');
  2627.                 if(isset($this->PageLinks[$n])) {
  2628.                     //Links
  2629.                     $annots='/Annots [';
  2630.                     foreach($this->PageLinks[$nas $pl{
  2631.                         $rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
  2632.                         $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
  2633.                         if(is_string($pl[4])) {
  2634.                             $annots.='/A <</S /URI /URI ('.$this->_escape($pl[4]).')>>>>';
  2635.                         }
  2636.                         else {
  2637.                             $l=$this->links[$pl[4]];
  2638.                             $h=isset($this->OrientationChanges[$l[0]]$wPt $hPt;
  2639.                             $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k);
  2640.                         }
  2641.                     }
  2642.                     $this->_out($annots.']');
  2643.                 }
  2644.                 $this->_out('/Contents '.($this->n+1).' 0 R>>');
  2645.                 $this->_out('endobj');
  2646.                 //Page content
  2647.                 $p=($this->compressgzcompress($this->pages[$n]$this->pages[$n];
  2648.                 $this->_newobj();
  2649.                 $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  2650.                 $this->_putstream($p);
  2651.                 $this->_out('endobj');
  2652.             }
  2653.             //Pages root
  2654.             $this->offsets[1]=strlen($this->buffer);
  2655.             $this->_out('1 0 obj');
  2656.             $this->_out('<</Type /Pages');
  2657.             $kids='/Kids [';
  2658.             for($i=0;$i<$nb;$i++{
  2659.                 $kids.=(3+2*$i).' 0 R ';
  2660.             }
  2661.             $this->_out($kids.']');
  2662.             $this->_out('/Count '.$nb);
  2663.             $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt));
  2664.             $this->_out('>>');
  2665.             $this->_out('endobj');
  2666.         }
  2667.  
  2668.         /**
  2669.         * Adds fonts
  2670.         * _putfonts
  2671.         * @access protected
  2672.         */
  2673.         protected function _putfonts({
  2674.             $nf=$this->n;
  2675.             foreach($this->diffs as $diff{
  2676.                 //Encodings
  2677.                 $this->_newobj();
  2678.                 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  2679.                 $this->_out('endobj');
  2680.             }
  2681.             $mqr=get_magic_quotes_runtime();
  2682.             set_magic_quotes_runtime(0);
  2683.             foreach($this->FontFiles as $file=>$info{
  2684.                 //Font file embedding
  2685.                 $this->_newobj();
  2686.                 $this->FontFiles[$file]['n']=$this->n;
  2687.                 $font='';
  2688.                 $f=fopen($this->_getfontpath().$file,'rb',1);
  2689.                 if(!$f{
  2690.                     $this->Error('Font file not found');
  2691.                 }
  2692.                 while(!feof($f)) {
  2693.                     $font .= fread($f8192);
  2694.                 }
  2695.                 fclose($f);
  2696.                 $compressed=(substr($file,-2)=='.z');
  2697.                 if(!$compressed && isset($info['length2'])) {
  2698.                     $header=(ord($font{0})==128);
  2699.                     if($header{
  2700.                         //Strip first binary header
  2701.                         $font=substr($font,6);
  2702.                     }
  2703.                     if($header && ord($font{$info['length1']})==128{
  2704.                         //Strip second binary header
  2705.                         $font=substr($font,0,$info['length1']).substr($font,$info['length1']+6);
  2706.                     }
  2707.                 }
  2708.                 $this->_out('<</Length '.strlen($font));
  2709.                 if($compressed{
  2710.                     $this->_out('/Filter /FlateDecode');
  2711.                 }
  2712.                 $this->_out('/Length1 '.$info['length1']);
  2713.                 if(isset($info['length2'])) {
  2714.                     $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  2715.                 }
  2716.                 $this->_out('>>');
  2717.                 $this->_putstream($font);
  2718.                 $this->_out('endobj');
  2719.             }
  2720.             set_magic_quotes_runtime($mqr);
  2721.             foreach($this->fonts as $k=>$font{
  2722.                 //Font objects
  2723.                 $this->fonts[$k]['n']=$this->n+1;
  2724.                 $type=$font['type'];
  2725.                 $name=$font['name'];
  2726.                 if($type=='core'{
  2727.                     //Standard font
  2728.                     $this->_newobj();
  2729.                     $this->_out('<</Type /Font');
  2730.                     $this->_out('/BaseFont /'.$name);
  2731.                     $this->_out('/Subtype /Type1');
  2732.                     if($name!='Symbol' && $name!='ZapfDingbats'{
  2733.                         $this->_out('/Encoding /WinAnsiEncoding');
  2734.                     }
  2735.                     $this->_out('>>');
  2736.                     $this->_out('endobj');
  2737.                 elseif($type=='Type1' || $type=='TrueType'{
  2738.                     //Additional Type1 or TrueType font
  2739.                     $this->_newobj();
  2740.                     $this->_out('<</Type /Font');
  2741.                     $this->_out('/BaseFont /'.$name);
  2742.                     $this->_out('/Subtype /'.$type);
  2743.                     $this->_out('/FirstChar 32 /LastChar 255');
  2744.                     $this->_out('/Widths '.($this->n+1).' 0 R');
  2745.                     $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  2746.                     if($font['enc']{
  2747.                         if(isset($font['diff'])) {
  2748.                             $this->_out('/Encoding '.($nf+$font['diff']).' 0 R');
  2749.                         else {
  2750.                             $this->_out('/Encoding /WinAnsiEncoding');
  2751.                         }
  2752.                     }
  2753.                     $this->_out('>>');
  2754.                     $this->_out('endobj');
  2755.                     //Widths
  2756.                     $this->_newobj();
  2757.                     $cw=&$font['cw'];
  2758.                     $s='[';
  2759.                     for($i=32;$i<=255;$i++{
  2760.                         $s.=$cw[chr($i)].' ';
  2761.                     }
  2762.                     $this->_out($s.']');
  2763.                     $this->_out('endobj');
  2764.                     //Descriptor
  2765.                     $this->_newobj();
  2766.                     $s='<</Type /FontDescriptor /FontName /'.$name;
  2767.                     foreach($font['desc'as $k=>$v{
  2768.                         $s.=' /'.$k.' '.$v;
  2769.                     }
  2770.                     $file $font['file'];
  2771.                     if($file{
  2772.                         $s.=' /FontFile'.($type=='Type1' '' '2').' '.$this->FontFiles[$file]['n'].' 0 R';
  2773.                     }
  2774.                     $this->_out($s.'>>');
  2775.                     $this->_out('endobj');
  2776.                 else {
  2777.                     //Allow for additional types
  2778.                     $mtd='_put'.strtolower($type);
  2779.                     if(!method_exists($this$mtd)) {
  2780.                         $this->Error('Unsupported font type: '.$type);
  2781.                     }
  2782.                     $this->$mtd($font);
  2783.                 }
  2784.             }
  2785.         }
  2786.  
  2787.         /**
  2788.         * _putimages
  2789.         * @access protected
  2790.         */
  2791.         protected function _putimages({
  2792.             $filter=($this->compress'/Filter /FlateDecode ' '';
  2793.             reset($this->images);
  2794.             while(list($file,$info)=each($this->images)) {
  2795.                 $this->_newobj();
  2796.                 $this->images[$file]['n']=$this->n;
  2797.                 $this->_out('<</Type /XObject');
  2798.                 $this->_out('/Subtype /Image');
  2799.                 $this->_out('/Width '.$info['w']);
  2800.                 $this->_out('/Height '.$info['h']);
  2801.                 if($info['cs']=='Indexed'{
  2802.                     $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
  2803.                 }
  2804.                 else {
  2805.                     $this->_out('/ColorSpace /'.$info['cs']);
  2806.                     if($info['cs']=='DeviceCMYK'{
  2807.                         $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  2808.                     }
  2809.                 }
  2810.                 $this->_out('/BitsPerComponent '.$info['bpc']);
  2811.                 if(isset($info['f'])) {
  2812.                     $this->_out('/Filter /'.$info['f']);
  2813.                 }
  2814.                 if(isset($info['parms'])) {
  2815.                     $this->_out($info['parms']);
  2816.                 }
  2817.                 if(isset($info['trns']and is_array($info['trns'])) {
  2818.                     $trns='';
  2819.                     for($i=0;$i<count($info['trns']);$i++{
  2820.                         $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  2821.                     }
  2822.                     $this->_out('/Mask ['.$trns.']');
  2823.                 }
  2824.                 $this->_out('/Length '.strlen($info['data']).'>>');
  2825.                 $this->_putstream($info['data']);
  2826.                 unset($this->images[$file]['data']);
  2827.                 $this->_out('endobj');
  2828.                 //Palette
  2829.                 if($info['cs']=='Indexed'{
  2830.                     $this->_newobj();
  2831.                     $pal=($this->compressgzcompress($info['pal']$info['pal'];
  2832.                     $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  2833.                     $this->_putstream($pal);
  2834.                     $this->_out('endobj');
  2835.                 }
  2836.             }
  2837.         }
  2838.  
  2839.         /**
  2840.         * _putxobjectdict
  2841.         * @access protected
  2842.         */
  2843.         function _putxobjectdict({
  2844.             foreach($this->images as $image{
  2845.                 $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  2846.             }
  2847.         }
  2848.  
  2849.         /**
  2850.         * _putresourcedict
  2851.         * @access protected
  2852.         */
  2853.         function _putresourcedict(){
  2854.             $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  2855.             $this->_out('/Font <<');
  2856.             foreach($this->fonts as $font{
  2857.                 $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  2858.             }
  2859.             $this->_out('>>');
  2860.             $this->_out('/XObject <<');
  2861.             $this->_putxobjectdict();
  2862.             $this->_out('>>');
  2863.         }
  2864.  
  2865.         /**
  2866.         * _putresources
  2867.         * @access protected
  2868.         */
  2869.         function _putresources({
  2870.             $this->_putfonts();
  2871.             $this->_putimages();
  2872.             //Resource dictionary
  2873.             $this->offsets[2]=strlen($this->buffer);
  2874.             $this->_out('2 0 obj');
  2875.             $this->_out('<<');
  2876.             $this->_putresourcedict();
  2877.             $this->_out('>>');
  2878.             $this->_out('endobj');
  2879.         }
  2880.         
  2881.         /**
  2882.         * _putinfo
  2883.         * @access protected
  2884.         */
  2885.         protected function _putinfo({
  2886.             $this->_out('/Producer '.$this->_textstring(PDF_PRODUCER));
  2887.             if(!empty($this->title)) {
  2888.                 $this->_out('/Title '.$this->_textstring($this->title));
  2889.             }
  2890.             if(!empty($this->subject)) {
  2891.                 $this->_out('/Subject '.$this->_textstring($this->subject));
  2892.             }
  2893.             if(!empty($this->author)) {
  2894.                 $this->_out('/Author '.$this->_textstring($this->author));
  2895.             }
  2896.             if(!empty($this->keywords)) {
  2897.                 $this->_out('/Keywords '.$this->_textstring($this->keywords));
  2898.             }
  2899.             if(!empty($this->creator)) {
  2900.                 $this->_out('/Creator '.$this->_textstring($this->creator));
  2901.             }
  2902.             $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis')));
  2903.         }
  2904.  
  2905.         /**
  2906.         * _putcatalog
  2907.         * @access protected
  2908.         */
  2909.         protected function _putcatalog({
  2910.             $this->_out('/Type /Catalog');
  2911.             $this->_out('/Pages 1 0 R');
  2912.             if($this->ZoomMode=='fullpage'{
  2913.                 $this->_out('/OpenAction [3 0 R /Fit]');
  2914.             }
  2915.             elseif($this->ZoomMode=='fullwidth'{
  2916.                 $this->_out('/OpenAction [3 0 R /FitH null]');
  2917.             }
  2918.             elseif($this->ZoomMode=='real'{
  2919.                 $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  2920.             }
  2921.             elseif(!is_string($this->ZoomMode)) {
  2922.                 $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
  2923.             }
  2924.             if($this->LayoutMode=='single'{
  2925.                 $this->_out('/PageLayout /SinglePage');
  2926.             }
  2927.             elseif($this->LayoutMode=='continuous'{
  2928.                 $this->_out('/PageLayout /OneColumn');
  2929.             }
  2930.             elseif($this->LayoutMode=='two'{
  2931.                 $this->_out('/PageLayout /TwoColumnLeft');
  2932.             }
  2933.         }
  2934.  
  2935.         /**
  2936.         * _puttrailer
  2937.         * @access protected
  2938.         */
  2939.         protected function _puttrailer({
  2940.             $this->_out('/Size '.($this->n+1));
  2941.             $this->_out('/Root '.$this->n.' 0 R');
  2942.             $this->_out('/Info '.($this->n-1).' 0 R');
  2943.         }
  2944.  
  2945.         /**
  2946.         * _putheader
  2947.         * @access protected
  2948.         */
  2949.         function _putheader({
  2950.             $this->_out('%PDF-'.$this->PDFVersion);
  2951.         }
  2952.  
  2953.         /**
  2954.         * _enddoc
  2955.         * @access protected
  2956.         */
  2957.         protected function _enddoc({
  2958.             $this->_putheader();
  2959.             $this->_putpages();
  2960.             $this->_putresources();
  2961.             //Info
  2962.             $this->_newobj();
  2963.             $this->_out('<<');
  2964.             $this->_putinfo();
  2965.             $this->_out('>>');
  2966.             $this->_out('endobj');
  2967.             //Catalog
  2968.             $this->_newobj();
  2969.             $this->_out('<<');
  2970.             $this->_putcatalog();
  2971.             $this->_out('>>');
  2972.             $this->_out('endobj');
  2973.             //Cross-ref
  2974.             $o=strlen($this->buffer);
  2975.             $this->_out('xref');
  2976.             $this->_out('0 '.($this->n+1));
  2977.             $this->_out('0000000000 65535 f ');
  2978.             for($i=1;$i<=$this->n;$i++{
  2979.                 $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  2980.             }
  2981.             //Trailer
  2982.             $this->_out('trailer');
  2983.             $this->_out('<<');
  2984.             $this->_puttrailer();
  2985.             $this->_out('>>');
  2986.             $this->_out('startxref');
  2987.             $this->_out($o);
  2988.             $this->_out('%%EOF');
  2989.             $this->state=3;
  2990.         }
  2991.  
  2992.         /**
  2993.         * _beginpage
  2994.         * @access protected
  2995.         */
  2996.         protected function _beginpage($orientation{
  2997.             $this->page++;
  2998.             $this->pages[$this->page]='';
  2999.             $this->state=2;
  3000.             $this->x=$this->lMargin;
  3001.             $this->y=$this->tMargin;
  3002.             $this->FontFamily='';
  3003.             //Page orientation
  3004.             if(empty($orientation)) {
  3005.                 $orientation=$this->DefOrientation;
  3006.             }
  3007.             else {
  3008.                 $orientation=strtoupper($orientation{0});
  3009.                 if($orientation!=$this->DefOrientation{
  3010.                     $this->OrientationChanges[$this->page]=true;
  3011.                 }
  3012.             }
  3013.             if($orientation!=$this->CurOrientation{
  3014.                 //Change orientation
  3015.                 if($orientation=='P'{
  3016.                     $this->wPt=$this->fwPt;
  3017.                     $this->hPt=$this->fhPt;
  3018.                     $this->w=$this->fw;
  3019.                     $this->h=$this->fh;
  3020.                 }
  3021.                 else {
  3022.                     $this->wPt=$this->fhPt;
  3023.                     $this->hPt=$this->fwPt;
  3024.                     $this->w=$this->fh;
  3025.                     $this->h=$this->fw;
  3026.                 }
  3027.                 $this->PageBreakTrigger=$this->h-$this->bMargin;
  3028.                 $this->CurOrientation=$orientation;
  3029.             }
  3030.         }
  3031.  
  3032.         /**
  3033.         * End of page contents
  3034.         * @access protected
  3035.         */
  3036.         protected function _endpage({
  3037.             $this->state=1;
  3038.         }
  3039.  
  3040.         /**
  3041.         * Begin a new object
  3042.         * @access protected
  3043.         */
  3044.         protected function _newobj({
  3045.             $this->n++;
  3046.             $this->offsets[$this->n]=strlen($this->buffer);
  3047.             $this->_out($this->n.' 0 obj');
  3048.         }
  3049.  
  3050.         /**
  3051.         * Underline text
  3052.         * @access protected
  3053.         */
  3054.         protected function _dounderline($x,$y,$txt{
  3055.             $up $this->CurrentFont['up'];
  3056.             $ut $this->CurrentFont['ut'];
  3057.             $w $this->GetStringWidth($txt$this->ws * substr_count($txt,' ');
  3058.             return sprintf('%.2f %.2f %.2f %.2f re f'$x $this->k($this->h - ($y $up 1000 $this->FontSize)) $this->k$w $this->k-$ut 1000 $this->FontSizePt);
  3059.         }
  3060.  
  3061.         /**
  3062.         * Extract info from a JPEG file
  3063.         * @access protected
  3064.         */
  3065.         protected function _parsejpg($file{
  3066.             $a=GetImageSize($file);
  3067.             if(empty($a)) {
  3068.                 $this->Error('Missing or incorrect image file: '.$file);
  3069.             }
  3070.             if($a[2]!=2{
  3071.                 $this->Error('Not a JPEG file: '.$file);
  3072.             }
  3073.             if(!isset($a['channels']or $a['channels']==3{
  3074.                 $colspace='DeviceRGB';
  3075.             }
  3076.             elseif($a['channels']==4{
  3077.                 $colspace='DeviceCMYK';
  3078.             }
  3079.             else {
  3080.                 $colspace='DeviceGray';
  3081.             }
  3082.             $bpc=isset($a['bits']$a['bits'8;
  3083.             //Read whole file
  3084.             $f=fopen($file,'rb');
  3085.             $data='';
  3086.             while(!feof($f)) {
  3087.                 $data.=fread($f,4096);
  3088.             }
  3089.             fclose($f);
  3090.             return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
  3091.         }
  3092.  
  3093.         /**
  3094.         * Extract info from a PNG file
  3095.         * @access protected
  3096.         */
  3097.         protected function _parsepng($file{
  3098.             $f=fopen($file,'rb');
  3099.             if(empty($f)) {
  3100.                 $this->Error('Can\'t open image file: '.$file);
  3101.             }
  3102.             //Check signature
  3103.             if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  3104.                 $this->Error('Not a PNG file: '.$file);
  3105.             }
  3106.             //Read header chunk
  3107.             fread($f,4);
  3108.             if(fread($f,4)!='IHDR'{
  3109.                 $this->Error('Incorrect PNG file: '.$file);
  3110.             }
  3111.             $w=$this->_freadint($f);
  3112.             $h=$this->_freadint($f);
  3113.             $bpc=ord(fread($f,1));
  3114.             if($bpc>8{
  3115.                 $this->Error('16-bit depth not supported: '.$file);
  3116.             }
  3117.             $ct=ord(fread($f,1));
  3118.             if($ct==0{
  3119.                 $colspace='DeviceGray';
  3120.             }
  3121.             elseif($ct==2{
  3122.                 $colspace='DeviceRGB';
  3123.             }
  3124.             elseif($ct==3{
  3125.                 $colspace='Indexed';
  3126.             }
  3127.             else {
  3128.                 $this->Error('Alpha channel not supported: '.$file);
  3129.             }
  3130.             if(ord(fread($f,1))!=0{
  3131.                 $this->Error('Unknown compression method: '.$file);
  3132.             }
  3133.             if(ord(fread($f,1))!=0{
  3134.                 $this->Error('Unknown filter method: '.$file);
  3135.             }
  3136.             if(ord(fread($f,1))!=0{
  3137.                 $this->Error('Interlacing not supported: '.$file);
  3138.             }
  3139.             fread($f,4);
  3140.             $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  3141.             //Scan chunks looking for palette, transparency and image data
  3142.             $pal='';
  3143.             $trns='';
  3144.             $data='';
  3145.             do {
  3146.                 $n=$this->_freadint($f);
  3147.                 $type=fread($f,4);
  3148.                 if($type=='PLTE'{
  3149.                     //Read palette
  3150.                     $pal=fread($f,$n);
  3151.                     fread($f,4);
  3152.                 }
  3153.                 elseif($type=='tRNS'{
  3154.                     //Read transparency info
  3155.                     $t=fread($f,$n);
  3156.                     if($ct==0{
  3157.                         $trns=array(ord(substr($t,1,1)));
  3158.                     }
  3159.                     elseif($ct==2{
  3160.                         $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  3161.                     }
  3162.                     else {
  3163.                         $pos=strpos($t,chr(0));
  3164.                         if($pos!==false{
  3165.                             $trns=array($pos);
  3166.                         }
  3167.                     }
  3168.                     fread($f,4);
  3169.                 }
  3170.                 elseif($type=='IDAT'{
  3171.                     //Read image data block
  3172.                     $data.=fread($f,$n);
  3173.                     fread($f,4);
  3174.                 }
  3175.                 elseif($type=='IEND'{
  3176.                     break;
  3177.                 }
  3178.                 else {
  3179.                     fread($f,$n+4);
  3180.                 }
  3181.             }
  3182.             while($n);
  3183.             if($colspace=='Indexed' and empty($pal)) {
  3184.                 $this->Error('Missing palette in '.$file);
  3185.             }
  3186.             fclose($f);
  3187.             return array('w'=>$w'h'=>$h'cs'=>$colspace'bpc'=>$bpc'f'=>'FlateDecode''parms'=>$parms'pal'=>$pal'trns'=>$trns'data'=>$data);
  3188.         }
  3189.  
  3190.         /**
  3191.         * Read a 4-byte integer from file
  3192.         * @access protected
  3193.         */
  3194.         protected function _freadint($f{
  3195.             //Read a 4-byte integer from file
  3196.             $a=unpack('Ni',fread($f,4));
  3197.             return $a['i'];
  3198.         }
  3199.  
  3200.         /**
  3201.         * Format a text string
  3202.         * @access protected
  3203.         */
  3204.         protected function _textstring($s{
  3205.             if($this->isunicode{
  3206.                 //Convert string to UTF-16BE
  3207.                 $s $this->UTF8ToUTF16BE($strue);
  3208.             }
  3209.             return '('$this->_escape($s).')';
  3210.         }
  3211.  
  3212.         /**
  3213.         * Format a text string
  3214.         * @access protected
  3215.         */
  3216.         function _escapetext($s{
  3217.             if($this->isunicode{
  3218.                 //Convert string to UTF-16BE
  3219.                 $s $this->UTF8ToUTF16BE($sfalse);
  3220.             }
  3221.             return $this->_escape($s);
  3222.         }
  3223.  
  3224.         /**
  3225.         * Add \ before \, ( and )
  3226.         * @access protected
  3227.         */
  3228.         protected function _escape($s{
  3229.             // the chr(13) substitution fixes the Bugs item #1421290.
  3230.             return strtr($sarray(')' => '\\)''(' => '\\(''\\' => '\\\\'chr(13=> '\r'));
  3231.         }
  3232.  
  3233.         /**
  3234.         *
  3235.         * @access protected
  3236.         */
  3237.         protected function _putstream($s{
  3238.             $this->_out('stream');
  3239.             $this->_out($s);
  3240.             $this->_out('endstream');
  3241.         }
  3242.  
  3243.         /**
  3244.         * Add a line to the document
  3245.         * @access protected
  3246.         */
  3247.         protected function _out($s{
  3248.             if($this->state==2{
  3249.                 $this->pages[$this->page.= $s."\n";
  3250.             }
  3251.             else {
  3252.                 $this->buffer .= $s."\n";
  3253.             }
  3254.         }
  3255.  
  3256.         /**
  3257.         * Adds unicode fonts.<br>
  3258.         * Based on PDF Reference 1.3 (section 5)
  3259.         * @access protected
  3260.         * @author Nicola Asuni
  3261.         * @since 1.52.0.TC005 (2005-01-05)
  3262.         */
  3263.         protected function _puttruetypeunicode($font{
  3264.             // Type0 Font
  3265.             // A composite font composed of other fonts, organized hierarchically
  3266.             $this->_newobj();
  3267.             $this->_out('<</Type /Font');
  3268.             $this->_out('/Subtype /Type0');
  3269.             $this->_out('/BaseFont /'.$font['name'].'');
  3270.             $this->_out('/Encoding /Identity-H')//The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry, Ordering, and Supplement values.
  3271.             $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  3272.             $this->_out('/ToUnicode '.($this->n + 2).' 0 R');
  3273.             $this->_out('>>');
  3274.             $this->_out('endobj');
  3275.             
  3276.             // CIDFontType2
  3277.             // A CIDFont whose glyph descriptions are based on TrueType font technology
  3278.             $this->_newobj();
  3279.             $this->_out('<</Type /Font');
  3280.             $this->_out('/Subtype /CIDFontType2');
  3281.             $this->_out('/BaseFont /'.$font['name'].'');
  3282.             $this->_out('/CIDSystemInfo '.($this->n + 2).' 0 R')
  3283.             $this->_out('/FontDescriptor '.($this->n + 3).' 0 R');
  3284.             if (isset($font['desc']['MissingWidth'])){
  3285.                 $this->_out('/DW '.$font['desc']['MissingWidth'].'')// The default width for glyphs in the CIDFont MissingWidth
  3286.             }
  3287.             $w "";
  3288.             foreach ($font['cw'as $cid => $width{
  3289.                 $w .= ''.$cid.' ['.$width.'] '// define a specific width for each individual CID
  3290.             }
  3291.             $this->_out('/W ['.$w.']')// A description of the widths for the glyphs in the CIDFont
  3292.             $this->_out('/CIDToGIDMap '.($this->n + 4).' 0 R');
  3293.             $this->_out('>>');
  3294.             $this->_out('endobj');
  3295.             
  3296.             // ToUnicode
  3297.             // is a stream object that contains the definition of the CMap
  3298.             // (PDF Reference 1.3 chap. 5.9)
  3299.             $this->_newobj();
  3300.             $this->_out('<</Length 383>>');
  3301.             $this->_out('stream');
  3302.             $this->_out('/CIDInit /ProcSet findresource begin');
  3303.             $this->_out('12 dict begin');
  3304.             $this->_out('begincmap');
  3305.             $this->_out('/CIDSystemInfo');
  3306.             $this->_out('<</Registry (Adobe)');
  3307.             $this->_out('/Ordering (UCS)');
  3308.             $this->_out('/Supplement 0');
  3309.             $this->_out('>> def');
  3310.             $this->_out('/CMapName /Adobe-Identity-UCS def');
  3311.             $this->_out('/CMapType 2 def');
  3312.             $this->_out('1 begincodespacerange');
  3313.             $this->_out('<0000> <FFFF>');
  3314.             $this->_out('endcodespacerange');
  3315.             $this->_out('1 beginbfrange');
  3316.             $this->_out('<0000> <FFFF> <0000>');
  3317.             $this->_out('endbfrange');
  3318.             $this->_out('endcmap');
  3319.             $this->_out('CMapName currentdict /CMap defineresource pop');
  3320.             $this->_out('end');
  3321.             $this->_out('end');
  3322.             $this->_out('endstream');
  3323.             $this->_out('endobj');
  3324.             
  3325.             // CIDSystemInfo dictionary
  3326.             // A dictionary containing entries that define the character collection of the CIDFont.
  3327.             $this->_newobj();
  3328.             $this->_out('<</Registry (Adobe)')// A string identifying an issuer of character collections
  3329.             $this->_out('/Ordering (UCS)')// A string that uniquely names a character collection issued by a specific registry
  3330.             $this->_out('/Supplement 0')// The supplement number of the character collection.
  3331.             $this->_out('>>');
  3332.             $this->_out('endobj');
  3333.             
  3334.             // Font descriptor
  3335.             // A font descriptor describing the CIDFont default metrics other than its glyph widths
  3336.             $this->_newobj();
  3337.             $this->_out('<</Type /FontDescriptor');
  3338.             $this->_out('/FontName /'.$font['name']);
  3339.             foreach ($font['desc'as $key => $value{
  3340.                 $this->_out('/'.$key.' '.$value);
  3341.             }
  3342.             if ($font['file']{
  3343.                 // A stream containing a TrueType font program
  3344.                 $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R');
  3345.             }
  3346.             $this->_out('>>');
  3347.             $this->_out('endobj');
  3348.  
  3349.             // Embed CIDToGIDMap
  3350.             // A specification of the mapping from CIDs to glyph indices
  3351.             $this->_newobj();
  3352.             $ctgfile $this->_getfontpath().$font['ctg'];
  3353.             if(!file_exists($ctgfile)) {
  3354.                 $this->Error('Font file not found: '.$ctgfile);
  3355.             }
  3356.             $size filesize($ctgfile);
  3357.             $this->_out('<</Length '.$size.'');
  3358.             if(substr($ctgfile-2== '.z'// check file extension
  3359.                 /* Decompresses data encoded using the public-domain 
  3360.                 zlib/deflate compression method, reproducing the 
  3361.                 original text or binary data */
  3362.                 $this->_out('/Filter /FlateDecode');
  3363.             }
  3364.             $this->_out('>>');
  3365.             $this->_putstream(file_get_contents($ctgfile));
  3366.             $this->_out('endobj');
  3367.         }
  3368.  
  3369.          /**
  3370.          * Converts UTF-8 strings to codepoints array.<br>
  3371.          * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  3372.          * Based on: http://www.faqs.org/rfcs/rfc3629.html
  3373.          * <pre>
  3374.          *       Char. number range  |        UTF-8 octet sequence
  3375.          *       (hexadecimal)    |              (binary)
  3376.          *    --------------------+-----------------------------------------------
  3377.          *    0000 0000-0000 007F | 0xxxxxxx
  3378.          *    0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  3379.          *    0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  3380.          *    0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  3381.          *    ---------------------------------------------------------------------
  3382.          *
  3383.          *   ABFN notation:
  3384.          *   ---------------------------------------------------------------------
  3385.          *   UTF8-octets = *( UTF8-char )
  3386.          *   UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  3387.          *   UTF8-1      = %x00-7F
  3388.          *   UTF8-2      = %xC2-DF UTF8-tail
  3389.          *
  3390.          *   UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  3391.          *                 %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  3392.          *   UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  3393.          *                 %xF4 %x80-8F 2( UTF8-tail )
  3394.          *   UTF8-tail   = %x80-BF
  3395.          *   ---------------------------------------------------------------------
  3396.          * </pre>
  3397.          * @param string $str string to process.
  3398.          * @return array containing codepoints (UTF-8 characters values)
  3399.          * @access protected
  3400.          * @author Nicola Asuni
  3401.          * @since 1.53.0.TC005 (2005-01-05)
  3402.          */
  3403.         protected function UTF8StringToArray($str{
  3404.             if(!$this->isunicode{
  3405.                 return $str// string is not in unicode
  3406.             }
  3407.             $unicode array()// array containing unicode values
  3408.             $bytes  array()// array containing single character byte sequences
  3409.             $numbytes  1// number of octetc needed to represent the UTF-8 character
  3410.             
  3411.             $str .= ""// force $str to be a string
  3412.             $length strlen($str);
  3413.             
  3414.             for($i 0$i $length$i++{
  3415.                 $char ord($str{$i})// get one string character at time
  3416.                 if(count($bytes== 0// get starting octect
  3417.                     if ($char <= 0x7F{
  3418.                         $unicode[$char// use the character "as is" because is ASCII
  3419.                         $numbytes 1;
  3420.                     elseif (($char >> 0x05== 0x06// 2 bytes character (0x06 = 110 BIN)
  3421.                         $bytes[($char 0xC0<< 0x06
  3422.                         $numbytes 2;
  3423.                     elseif (($char >> 0x04== 0x0E// 3 bytes character (0x0E = 1110 BIN)
  3424.                         $bytes[($char 0xE0<< 0x0C
  3425.                         $numbytes 3;
  3426.                     elseif (($char >> 0x03== 0x1E// 4 bytes character (0x1E = 11110 BIN)
  3427.                         $bytes[($char 0xF0<< 0x12
  3428.                         $numbytes 4;
  3429.                     else {
  3430.                         // use replacement character for other invalid sequences
  3431.                         $unicode[0xFFFD;
  3432.                         $bytes array();
  3433.                         $numbytes 1;
  3434.                     }
  3435.                 elseif (($char >> 0x06== 0x02// bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  3436.                     $bytes[$char 0x80;
  3437.                     if (count($bytes== $numbytes{
  3438.                         // compose UTF-8 bytes to a single unicode value
  3439.                         $char $bytes[0];
  3440.                         for($j 1$j $numbytes$j++{
  3441.                             $char += ($bytes[$j<< (($numbytes $j 10x06));
  3442.                         }
  3443.                         if ((($char >= 0xD800AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  3444.                             /* The definition of UTF-8 prohibits encoding character numbers between
  3445.                             U+D800 and U+DFFF, which are reserved for use with the UTF-16
  3446.                             encoding form (as surrogate pairs) and do not directly represent
  3447.                             characters. */
  3448.                             $unicode[0xFFFD// use replacement character
  3449.                         }
  3450.                         else {
  3451.                             $unicode[$char// add char to array
  3452.                         }
  3453.                         // reset data for next char
  3454.                         $bytes array()
  3455.                         $numbytes 1;
  3456.                     }
  3457.                 else {
  3458.                     // use replacement character for other invalid sequences
  3459.                     $unicode[0xFFFD;
  3460.                     $bytes array();
  3461.                     $numbytes 1;
  3462.                 }
  3463.             }
  3464.             return $unicode;
  3465.         }
  3466.         
  3467.         /**
  3468.          * Converts UTF-8 strings to UTF16-BE.<br>
  3469.          * Based on: http://www.faqs.org/rfcs/rfc2781.html
  3470.           * <pre>
  3471.          *   Encoding UTF-16:
  3472.          * 
  3473.           *   Encoding of a single character from an ISO 10646 character value to
  3474.          *    UTF-16 proceeds as follows. Let U be the character number, no greater
  3475.          *    than 0x10FFFF.
  3476.          * 
  3477.          *    1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  3478.          *       terminate.
  3479.          * 
  3480.          *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  3481.          *       U' must be less than or equal to 0xFFFFF. That is, U' can be
  3482.          *       represented in 20 bits.
  3483.          * 
  3484.          *    3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  3485.          *       0xDC00, respectively. These integers each have 10 bits free to
  3486.          *       encode the character value, for a total of 20 bits.
  3487.          * 
  3488.          *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  3489.          *       bits of W1 and the 10 low-order bits of U' to the 10 low-order
  3490.          *       bits of W2. Terminate.
  3491.          * 
  3492.          *    Graphically, steps 2 through 4 look like:
  3493.          *    U' = yyyyyyyyyyxxxxxxxxxx
  3494.          *    W1 = 110110yyyyyyyyyy
  3495.          *    W2 = 110111xxxxxxxxxx
  3496.          * </pre>
  3497.          * @param string $str string to process.
  3498.          * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  3499.          * @return string 
  3500.          * @access protected
  3501.          * @author Nicola Asuni
  3502.          * @since 1.53.0.TC005 (2005-01-05)
  3503.          * @uses UTF8StringToArray
  3504.          */
  3505.         protected function UTF8ToUTF16BE($str$setbom=true{
  3506.             if(!$this->isunicode{
  3507.                 return $str// string is not in unicode
  3508.             }
  3509.             $outstr ""// string to be returned
  3510.             $unicode $this->UTF8StringToArray($str)// array containing UTF-8 unicode values
  3511.             $numitems count($unicode);
  3512.             
  3513.             if ($setbom{
  3514.                 $outstr .= "\xFE\xFF"// Byte Order Mark (BOM)
  3515.             }
  3516.             foreach($unicode as $char{
  3517.                 if($char == 0xFFFD{
  3518.                     $outstr .= "\xFF\xFD"// replacement character
  3519.                 elseif ($char 0x10000{
  3520.                     $outstr .= chr($char >> 0x08);
  3521.                     $outstr .= chr($char 0xFF);
  3522.                 else {
  3523.                     $char -= 0x10000;
  3524.                     $w1 0xD800 ($char >> 0x10);
  3525.                     $w2 0xDC00 ($char 0x3FF);    
  3526.                     $outstr .= chr($w1 >> 0x08);
  3527.                     $outstr .= chr($w1 0xFF);
  3528.                     $outstr .= chr($w2 >> 0x08);
  3529.                     $outstr .= chr($w2 0xFF);
  3530.                 }
  3531.             }
  3532.             return $outstr;
  3533.         }
  3534.         
  3535.         // ====================================================
  3536.         
  3537.         /**
  3538.           * Set header font.
  3539.          * @param array $font font
  3540.          * @since 1.1
  3541.          */
  3542.         public function setHeaderFont($font{
  3543.             $this->header_font $font;
  3544.         }
  3545.         
  3546.         /**
  3547.           * Set footer font.
  3548.          * @param array $font font
  3549.          * @since 1.1
  3550.          */
  3551.         public function setFooterFont($font{
  3552.             $this->footer_font $font;
  3553.         }
  3554.         
  3555.         /**
  3556.           * Set language array.
  3557.          * @param array $language 
  3558.          * @since 1.1
  3559.          */
  3560.         public function setLanguageArray($language{
  3561.             $this->$language;
  3562.         }
  3563.         
  3564.         /**
  3565.           * Set document barcode.
  3566.          * @param string $bc barcode
  3567.          */
  3568.         public function setBarcode($bc=""{
  3569.             $this->barcode $bc;
  3570.         }
  3571.         
  3572.         /**
  3573.           * Print Barcode.
  3574.          * @param int $x x position in user units
  3575.          * @param int $y y position in user units
  3576.          * @param int $w width in user units
  3577.          * @param int $h height position in user units
  3578.          * @param string $type type of barcode (I25, C128A, C128B, C128C, C39)
  3579.          * @param string $style barcode style
  3580.          * @param string $font font for text
  3581.          * @param int $xres x resolution
  3582.          * @param string $code code to print
  3583.          */
  3584.         public function writeBarcode($x$y$w$h$type$style$font$xres$code{
  3585.             require_once(dirname(__FILE__)."/barcode/barcode.php");
  3586.             require_once(dirname(__FILE__)."/barcode/i25object.php");
  3587.             require_once(dirname(__FILE__)."/barcode/c39object.php");
  3588.             require_once(dirname(__FILE__)."/barcode/c128aobject.php");
  3589.             require_once(dirname(__FILE__)."/barcode/c128bobject.php");
  3590.             require_once(dirname(__FILE__)."/barcode/c128cobject.php");
  3591.             
  3592.             if (empty($code)) {
  3593.                 return;
  3594.             }
  3595.             
  3596.             if (empty($style)) {
  3597.                 $style  BCS_ALIGN_LEFT;
  3598.                 $style |= BCS_IMAGE_PNG;
  3599.                 $style |= BCS_TRANSPARENT;
  3600.                 //$style |= BCS_BORDER;
  3601.                 //$style |= BCS_DRAW_TEXT;
  3602.                 //$style |= BCS_STRETCH_TEXT;
  3603.                 //$style |= BCS_REVERSE_COLOR;
  3604.             }
  3605.             if (empty($font)) {$font BCD_DEFAULT_FONT;}
  3606.             if (empty($xres)) {$xres BCD_DEFAULT_XRES;}
  3607.             
  3608.             $scale_factor 1.5 $xres $this->k;
  3609.             $bc_w round($w $scale_factor)//width in points
  3610.             $bc_h round($h $scale_factor)//height in points
  3611.             
  3612.             switch (strtoupper($type)) {
  3613.                 case "I25"{
  3614.                     $obj new I25Object($bc_w$bc_h$style$code);
  3615.                     break;
  3616.                 }
  3617.                 case "C128A"{
  3618.                     $obj new C128AObject($bc_w$bc_h$style$code);
  3619.                     break;
  3620.                 }
  3621.                 default:
  3622.                 case "C128B"{
  3623.                     $obj new C128BObject($bc_w$bc_h$style$code);
  3624.                     break;
  3625.                 }
  3626.                 case "C128C"{
  3627.                     $obj new C128CObject($bc_w$bc_h$style$code);
  3628.                     break;
  3629.                 }
  3630.                 case "C39"{
  3631.                     $obj new C39Object($bc_w$bc_h$style$code);
  3632.                     break;
  3633.                 }
  3634.             }
  3635.             
  3636.             $obj->SetFont($font);   
  3637.             $obj->DrawObject($xres);
  3638.             
  3639.             //use a temporary file....
  3640.             $tmpName tempnam(K_PATH_CACHE,'img');
  3641.             imagepng($obj->getImage()$tmpName);
  3642.             $this->Image($tmpName$x$y$w$h'png');
  3643.             $obj->DestroyObject();
  3644.             unset($obj);
  3645.             unlink($tmpName);
  3646.         }
  3647.         
  3648.         /**
  3649.           * Returns the PDF data.
  3650.          */
  3651.         public function getPDFData({
  3652.             if($this->state < 3{
  3653.                 $this->Close();
  3654.             }
  3655.             return $this->buffer;
  3656.         }
  3657.         
  3658.         // --- HTML PARSER FUNCTIONS ---
  3659.         
  3660.         /**
  3661.          * Allows to preserve some HTML formatting.<br />
  3662.          * Supports: 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
  3663.          * @param string $html text to display
  3664.          * @param boolean $ln if true add a new line after text (default = true)
  3665.          * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  3666.          */
  3667.         public function writeHTML($html$ln=true$fill=0{
  3668.             
  3669.             // store some variables
  3670.         $html=strip_tags($html,"<h1><h2><h3><h4><h5><h6><b><u><i><a><img><p><br><br/><strong><em><font><blockquote><li><ul><ol><hr><td><th><tr><table><sup><sub><small>")//remove all unsupported tags
  3671.             //replace carriage returns, newlines and tabs
  3672.             $repTable array("\t" => " ""\n" => " ""\r" => " ""\0" => " ""\x0B" => " ")
  3673.             $html strtr($html$repTable);
  3674.             $pattern '/(<[^>]+>)/Uu';
  3675.             $a preg_split($pattern$html-1PREG_SPLIT_DELIM_CAPTURE PREG_SPLIT_NO_EMPTY)//explodes the string
  3676.             
  3677.             if (empty($this->lasth)) {
  3678.                 //set row height
  3679.                 $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO
  3680.             }
  3681.             
  3682.             foreach($a as $key=>$element{
  3683.                 if (!preg_match($pattern$element)) {
  3684.                     //Text
  3685.                     if($this->HREF{
  3686.                         $this->addHtmlLink($this->HREF$element$fill);
  3687.                     }
  3688.                     elseif($this->tdbegin{
  3689.                         if((strlen(trim($element)) 0AND ($element != "&nbsp;")) {
  3690.                             $this->Cell($this->tdwidth$this->tdheight$this->unhtmlentities($element)$this->tableborder''$this->tdalign$this->tdbgcolor);
  3691.                         }
  3692.                         elseif($element == "&nbsp;"{
  3693.                             $this->Cell($this->tdwidth$this->tdheight''$this->tableborder''$this->tdalign$this->tdbgcolor);
  3694.                         }
  3695.                     }
  3696.                     else {
  3697.                         $this->Write($this->lasthstripslashes($this->unhtmlentities($element))''$fill);
  3698.                     }
  3699.                 else {
  3700.                     $element substr($element1-1);
  3701.                     //Tag
  3702.                     if($element{0}=='/'{
  3703.                         $this->closedHTMLTagHandler(strtolower(substr($element1)));
  3704.                     }
  3705.                     else {
  3706.                         //Extract attributes
  3707.                         // get tag name
  3708.                         preg_match('/([a-zA-Z0-9]*)/'$element$tag);
  3709.                         $tag strtolower($tag[0]);
  3710.                         // get attributes
  3711.                         preg_match_all('/([^=\s]*)=["\']?([^"\']*)["\']?/'$element$attr_arrayPREG_PATTERN_ORDER);
  3712.                         $attr array()// reset attribute array
  3713.                         while(list($id,$name)=each($attr_array[1])) {
  3714.                             $attr[strtolower($name)$attr_array[2][$id];
  3715.                         }
  3716.                         $this->openHTMLTagHandler($tag$attr$fill);
  3717.                     }
  3718.                 }
  3719.             }
  3720.             if ($ln{
  3721.                 $this->Ln($this->lasth);
  3722.             }
  3723.         }
  3724.         
  3725.         /**
  3726.          * Prints a cell (rectangular area) with optional borders, background color and html text string. The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.<br />
  3727.          * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3728.          * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3729.          * @param float $h Cell minimum height. The cell extends automatically if needed.
  3730.          * @param float $x upper-left corner X coordinate
  3731.          * @param float $y upper-left corner Y coordinate
  3732.          * @param string $html html text to print. Default value: empty string.
  3733.          * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3734.          * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  3735.     Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3736.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3737.          * @see Cell()
  3738.          */
  3739.         public function writeHTMLCell($w$h$x$y$html=''$border=0$ln=0$fill=0{
  3740.             
  3741.             if (empty($this->lasth)) {
  3742.                 //set row height
  3743.                 $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO
  3744.             }
  3745.             
  3746.             if (empty($x)) {
  3747.                 $x $this->GetX();
  3748.             }
  3749.             if (empty($y)) {
  3750.                 $y $this->GetY();
  3751.             }
  3752.             
  3753.             // get current page number
  3754.             $pagenum $this->page;
  3755.             
  3756.             $this->SetX($x);
  3757.             $this->SetY($y);
  3758.                     
  3759.             if(empty($w)) {
  3760.                 $w $this->fw - $x $this->rMargin;
  3761.             }
  3762.             
  3763.             // store original margin values
  3764.             $lMargin $this->lMargin;
  3765.             $rMargin $this->rMargin;
  3766.             
  3767.             // set new margin values
  3768.             $this->SetLeftMargin($x);
  3769.             $this->SetRightMargin($this->fw - $x $w);
  3770.                     
  3771.             // calculate remaining vertical space on page
  3772.             $restspace $this->getPageHeight($this->GetY($this->getBreakMargin();
  3773.             
  3774.             $this->writeHTML($htmltrue$fill)// write html text
  3775.             
  3776.             $currentY =  $this->GetY();
  3777.             
  3778.             // check if a new page has been created
  3779.             if ($this->page > $pagenum{
  3780.                 // design a cell around the text on first page
  3781.                 $currentpage $this->page;
  3782.                 $this->page = $pagenum;
  3783.                 $this->SetY($this->getPageHeight($restspace $this->getBreakMargin());
  3784.                 $h $restspace 1;
  3785.                 $this->Cell($w$h""$border$ln'L'0);
  3786.                 // design a cell around the text on last page
  3787.                 $this->page = $currentpage;
  3788.                 $h $currentY $this->tMargin;
  3789.                 $this->SetY($this->tMargin)// put cursor at the beginning of text
  3790.                 $this->Cell($w$h""$border$ln'L'0);
  3791.             else {
  3792.                 $h max($h($currentY $y));
  3793.                 $this->SetY($y)// put cursor at the beginning of text
  3794.                 // design a cell around the text
  3795.                 $this->Cell($w$h""$border$ln'L'0);
  3796.             }
  3797.             
  3798.             // restore original margin values
  3799.             $this->SetLeftMargin($lMargin);
  3800.             $this->SetRightMargin($rMargin);
  3801.             
  3802.             if ($ln{
  3803.                 $this->Ln(0);
  3804.             }
  3805.         }
  3806.         
  3807.         /**
  3808.          * Process opening tags.
  3809.          * @param string $tag tag name (in uppercase)
  3810.          * @param string $attr tag attribute (in uppercase)
  3811.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3812.          * @access private
  3813.          */
  3814.         private function openHTMLTagHandler($tag$attr$fill=0{
  3815.             //Opening tag
  3816.             switch($tag{
  3817.                 case 'table'{
  3818.                     if ((isset($attr['border'])) AND ($attr['border'!= '')) {
  3819.                         $this->tableborder $attr['border'];
  3820.                     }
  3821.                     else {
  3822.                         $this->tableborder 0;
  3823.                     }
  3824.                     break;
  3825.                 }
  3826.                 case 'tr'{
  3827.                     break;
  3828.                 }
  3829.                 case 'td':
  3830.                 case 'th'{
  3831.                     if ((isset($attr['width'])) AND ($attr['width'!= '')) {
  3832.                         $this->tdwidth ($attr['width']/4);
  3833.                     }
  3834.                     else {
  3835.                         $this->tdwidth (($this->w - $this->lMargin - $this->rMargin$this->default_table_columns);
  3836.                     }
  3837.                     if ((isset($attr['height'])) AND ($attr['height'!= '')) {
  3838.                         $this->tdheight=($attr['height'$this->k);
  3839.                     }
  3840.                     else {
  3841.                         $this->tdheight $this->lasth;
  3842.                     }
  3843.                     if ((isset($attr['align'])) AND ($attr['align'!= '')) {
  3844.                         switch ($attr['align']{
  3845.                             case 'center'{
  3846.                                 $this->tdalign "C";
  3847.                                 break;
  3848.                             }
  3849.                             case 'right'{
  3850.                                 $this->tdalign "R";
  3851.                                 break;
  3852.                             }
  3853.                             default:
  3854.                             case 'left'{
  3855.                                 $this->tdalign "L";
  3856.                                 break;
  3857.                             }
  3858.                         }
  3859.                     }
  3860.                     if ((isset($attr['bgcolor'])) AND ($attr['bgcolor'!= '')) {
  3861.                         $coul $this->convertColorHexToDec($attr['bgcolor']);
  3862.                         $this->SetFillColor($coul['R']$coul['G']$coul['B']);
  3863.                         $this->tdbgcolor=true;
  3864.                     }
  3865.                     $this->tdbegin=true;
  3866.                     break;
  3867.                 }
  3868.                 case 'hr'{
  3869.                     $this->Ln();
  3870.                     if ((isset($attr['width'])) AND ($attr['width'!= '')) {
  3871.                         $hrWidth $attr['width'];
  3872.                     }
  3873.                     else {
  3874.                         $hrWidth $this->w - $this->lMargin - $this->rMargin;
  3875.                     }
  3876.                     $x $this->GetX();
  3877.                     $y $this->GetY();
  3878.                     $this->SetLineWidth(0.2);
  3879.                     $this->Line($x$y$x $hrWidth$y);
  3880.                     $this->SetLineWidth(0.2);
  3881.                     $this->Ln();
  3882.                     break;
  3883.                 }
  3884.                 case 'strong'{
  3885.                     $this->setStyle('b'true);
  3886.                     break;
  3887.                 }
  3888.                 case 'em'{
  3889.                     $this->setStyle('i'true);
  3890.                     break;
  3891.                 }
  3892.                 case 'b':
  3893.                 case 'i':
  3894.                 case 'u'{
  3895.                     $this->setStyle($tagtrue);
  3896.                     break;
  3897.                 }
  3898.                 case 'a'{
  3899.                     $this->HREF $attr['href'];
  3900.                     break;
  3901.                 }
  3902.                 case 'img'{
  3903.                     if(isset($attr['src'])) {
  3904.                         // replace relative path with real server path
  3905.                         $attr['src'str_replace(K_PATH_URL_CACHEK_PATH_CACHE$attr['src']);
  3906.                         if(!isset($attr['width'])) {
  3907.                             $attr['width'0;
  3908.                         }
  3909.                         if(!isset($attr['height'])) {
  3910.                             $attr['height'0;
  3911.                         }
  3912.                         
  3913.                         $this->Image($attr['src']$this->GetX(),$this->GetY()$this->pixelsToMillimeters($attr['width'])$this->pixelsToMillimeters($attr['height']));
  3914.                         //$this->SetX($this->img_rb_x);
  3915.                         $this->SetY($this->img_rb_y);
  3916.                         
  3917.                     }
  3918.                     break;
  3919.                 }
  3920.                 case 'ul'{
  3921.                     $this->listordered false;
  3922.                     $this->listcount 0;
  3923.                     break;
  3924.                 }
  3925.                 case 'ol'{
  3926.                     $this->listordered true;
  3927.                     $this->listcount 0;
  3928.                     break;
  3929.                 }
  3930.                 case 'li'{
  3931.                     $this->Ln();
  3932.                     if ($this->listordered{
  3933.                         $this->lispacer "    ".(++$this->listcount).". ";
  3934.                     }
  3935.                     else {
  3936.                         //unordered list simbol
  3937.                         $this->lispacer "    -  ";
  3938.                     }
  3939.                     $this->Write($this->lasth$this->lispacer''$fill);
  3940.                     break;
  3941.                 }
  3942.                 case 'blockquote':
  3943.                 case 'br'{
  3944.                     $this->Ln();
  3945.                     if(strlen($this->lispacer0{
  3946.                         $this->x += $this->GetStringWidth($this->lispacer);
  3947.                     }
  3948.                     break;
  3949.                 }
  3950.                 case 'p'{
  3951.                     $this->Ln();
  3952.                     $this->Ln();
  3953.                     break;
  3954.                 }
  3955.                 case 'sup'{
  3956.                     $currentFontSize $this->FontSize;
  3957.                     $this->tempfontsize $this->FontSizePt;
  3958.                     $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
  3959.                     $this->SetXY($this->GetX()$this->GetY((($currentFontSize $this->FontSize)*(K_SMALL_RATIO)));
  3960.                     break;
  3961.                 }
  3962.                 case 'sub'{
  3963.                     $currentFontSize $this->FontSize;
  3964.                     $this->tempfontsize $this->FontSizePt;
  3965.                     $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
  3966.                     $this->SetXY($this->GetX()$this->GetY((($currentFontSize $this->FontSize)*(K_SMALL_RATIO)));
  3967.                     break;
  3968.                 }
  3969.                 case 'small'{
  3970.                     $currentFontSize $this->FontSize;
  3971.                     $this->tempfontsize $this->FontSizePt;
  3972.                     $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
  3973.                     $this->SetXY($this->GetX()$this->GetY((($currentFontSize $this->FontSize)/3));
  3974.                     break;
  3975.                 }
  3976.                 case 'font'{
  3977.                     if (isset($attr['color']AND $attr['color']!=''{
  3978.                         $coul $this->convertColorHexToDec($attr['color']);
  3979.                         $this->SetTextColor($coul['R'],$coul['G'],$coul['B']);
  3980.                         $this->issetcolor=true;
  3981.                     }
  3982.                     if (isset($attr['face']and in_array(strtolower($attr['face'])$this->fontlist)) {
  3983.                         $this->SetFont(strtolower($attr['face']));
  3984.                         $this->issetfont=true;
  3985.                     }
  3986.                     if (isset($attr['size'])) {
  3987.                         $headsize intval($attr['size']);
  3988.                     else {
  3989.                         $headsize 0;
  3990.                     }
  3991.                     $currentFontSize $this->FontSize;
  3992.                     $this->tempfontsize $this->FontSizePt;
  3993.                     $this->SetFontSize($this->FontSizePt + $headsize);
  3994.                     $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  3995.                     break;
  3996.                 }
  3997.                 case 'h1'
  3998.                 case 'h2'
  3999.                 case 'h3'
  4000.                 case 'h4'
  4001.                 case 'h5'
  4002.                 case 'h6'{
  4003.                     $headsize (substr($tag1)) 2;
  4004.                     $currentFontSize $this->FontSize;
  4005.                     $this->tempfontsize $this->FontSizePt;
  4006.                     $this->SetFontSize($this->FontSizePt + $headsize);
  4007.                     $this->setStyle('b'true);
  4008.                     $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  4009.                     break;
  4010.                 }
  4011.             }
  4012.         }
  4013.         
  4014.         /**
  4015.          * Process closing tags.
  4016.          * @param string $tag tag name (in uppercase)
  4017.          * @access private
  4018.          */
  4019.         private function closedHTMLTagHandler($tag{
  4020.             //Closing tag
  4021.             switch($tag{
  4022.                 case 'td':
  4023.                 case 'th'{
  4024.                     $this->tdbegin false;
  4025.                     $this->tdwidth 0;
  4026.                     $this->tdheight 0;
  4027.                     $this->tdalign "L";
  4028.                     $this->tdbgcolor false;
  4029.                     $this->SetFillColor($this->prevFillColor[0]$this->prevFillColor[1]$this->prevFillColor[2]);
  4030.                     break;
  4031.                 }
  4032.                 case 'tr'{
  4033.                     $this->Ln();
  4034.                     break;
  4035.                 }
  4036.                 case 'table'{
  4037.                     $this->tableborder=0;
  4038.                     break;
  4039.                 }
  4040.                 case 'strong'{
  4041.                     $this->setStyle('b'false);
  4042.                     break;
  4043.                 }
  4044.                 case 'em'{
  4045.                     $this->setStyle('i'false);
  4046.                     break;
  4047.                 }
  4048.                 case 'b':
  4049.                 case 'i':
  4050.                 case 'u'{
  4051.                     $this->setStyle($tagfalse);
  4052.                     break;
  4053.                 }
  4054.                 case 'a'{
  4055.                     $this->HREF '';
  4056.                     break;
  4057.                 }
  4058.                 case 'sup'{
  4059.                     $currentFontSize $this->FontSize;
  4060.                     $this->SetFontSize($this->tempfontsize);
  4061.                     $this->tempfontsize $this->FontSizePt;
  4062.                     $this->SetXY($this->GetX()$this->GetY((($currentFontSize $this->FontSize)*(K_SMALL_RATIO)));
  4063.                     break;
  4064.                 }
  4065.                 case 'sub'{
  4066.                     $currentFontSize $this->FontSize;
  4067.                     $this->SetFontSize($this->tempfontsize);
  4068.                     $this->tempfontsize $this->FontSizePt;
  4069.                     $this->SetXY($this->GetX()$this->GetY((($currentFontSize $this->FontSize)*(K_SMALL_RATIO)));
  4070.                     break;
  4071.                 }
  4072.                 case 'small'{
  4073.                     $currentFontSize $this->FontSize;
  4074.                     $this->SetFontSize($this->tempfontsize);
  4075.                     $this->tempfontsize $this->FontSizePt;
  4076.                     $this->SetXY($this->GetX()$this->GetY((($this->FontSize - $currentFontSize)/3));
  4077.                     break;
  4078.                 }
  4079.                 case 'font'{
  4080.                     if ($this->issetcolor == true{
  4081.                         $this->SetTextColor($this->prevTextColor[0]$this->prevTextColor[1]$this->prevTextColor[2]);
  4082.                     }
  4083.                     if ($this->issetfont{
  4084.                         $this->FontFamily = $this->prevFontFamily;
  4085.                         $this->FontStyle = $this->prevFontStyle;
  4086.                         $this->SetFont($this->FontFamily);
  4087.                         $this->issetfont false;
  4088.                     }
  4089.                     $currentFontSize $this->FontSize;
  4090.                     $this->SetFontSize($this->tempfontsize);
  4091.                     $this->tempfontsize $this->FontSizePt;
  4092.                     //$this->TextColor = $this->prevTextColor;
  4093.                     $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  4094.                     break;
  4095.                 }
  4096.                 case 'ul'{
  4097.                     $this->Ln();
  4098.                     break;
  4099.                 }
  4100.                 case 'ol'{
  4101.                     $this->Ln();
  4102.                     break;
  4103.                 }
  4104.                 case 'li'{
  4105.                     $this->lispacer "";
  4106.                     break;
  4107.                 }
  4108.                 case 'h1'
  4109.                 case 'h2'
  4110.                 case 'h3'
  4111.                 case 'h4'
  4112.                 case 'h5'
  4113.                 case 'h6'{
  4114.                     $currentFontSize $this->FontSize;
  4115.                     $this->SetFontSize($this->tempfontsize);
  4116.                     $this->tempfontsize $this->FontSizePt;
  4117.                     $this->setStyle('b'false);
  4118.                     $this->Ln();
  4119.                     $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  4120.                     break;
  4121.                 }
  4122.                 default {
  4123.                     break;
  4124.                 }
  4125.             }
  4126.         }
  4127.         
  4128.         /**
  4129.          * Sets font style.
  4130.          * @param string $tag tag name (in lowercase)
  4131.          * @param boolean $enable 
  4132.          * @access private
  4133.          */
  4134.         private function setStyle($tag$enable{
  4135.             //Modify style and select corresponding font
  4136.             $this->$tag += ($enable : -1);
  4137.             $style='';
  4138.             foreach(array('b''i''u'as $s{
  4139.                 if($this->$s 0{
  4140.                     $style .= $s;
  4141.                 }
  4142.             }
  4143.             $this->SetFont(''$style);
  4144.         }
  4145.         
  4146.         /**
  4147.          * Output anchor link.
  4148.          * @param string $url link URL
  4149.          * @param string $name link name
  4150.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  4151.          * @access public
  4152.          */
  4153.         public function addHtmlLink($url$name$fill=0{
  4154.             //Put a hyperlink
  4155.             $this->SetTextColor(00255);
  4156.             $this->setStyle('u'true);
  4157.             $this->Write($this->lasth$name$url$fill);
  4158.             $this->setStyle('u'false);
  4159.             $this->SetTextColor(0);
  4160.         }
  4161.         
  4162.         /**
  4163.          * Returns an associative array (keys: R,G,B) from
  4164.          * a hex html code (e.g. #3FE5AA).
  4165.          * @param string $color hexadecimal html color [#rrggbb]
  4166.          * @return array 
  4167.          * @access private
  4168.          */
  4169.         private function convertColorHexToDec($color "#000000"){
  4170.             $tbl_color array();
  4171.             $tbl_color['R'hexdec(substr($color12));
  4172.             $tbl_color['G'hexdec(substr($color32));
  4173.             $tbl_color['B'hexdec(substr($color52));
  4174.             return $tbl_color;
  4175.         }
  4176.         
  4177.         /**
  4178.          * Converts pixels to millimeters in 72 dpi.
  4179.          * @param int $px pixels
  4180.          * @return float millimeters
  4181.          * @access private
  4182.          */
  4183.         private function pixelsToMillimeters($px){
  4184.             return $px 25.4 72;
  4185.         }
  4186.             
  4187.         /**
  4188.          * Reverse function for htmlentities.
  4189.          * Convert entities in UTF-8.
  4190.          *
  4191.          * @param $text_to_convert Text to convert.
  4192.          * @return string converted
  4193.          */
  4194.         public function unhtmlentities($text_to_convert{
  4195.             return html_entity_decode($text_to_convertENT_QUOTES$this->encoding);
  4196.         }
  4197.         
  4198.     // END OF CLASS
  4199.  
  4200.     //Handle special IE contype request
  4201.     if(isset($_SERVER['HTTP_USER_AGENT']AND ($_SERVER['HTTP_USER_AGENT']=='contype')) {
  4202.         header('Content-Type: application/pdf');
  4203.         exit;
  4204.     }
  4205.     
  4206. }
  4207. //============================================================+
  4208. // END OF FILE
  4209. //============================================================+
  4210. ?>

Documentation generated on Fri, 16 Oct 2009 09:39:51 +0200 by phpDocumentor 1.4.1