Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: com-tecnick-tcpdf

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /tcpdf/tcpdf.php

Documentation is available at tcpdf.php

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

Documentation generated on Mon, 05 Mar 2007 21:28:49 +0000 by phpDocumentor 1.3.1