2 //============================================================+
3 // File name : tcpdf.php
5 // Last Update : 2006-08-05
6 // Author : Nicola Asuni
7 // Version : 1.53.0.TC023_PHP4
8 // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
10 // Description : This is a PHP4 class for generating PDF files
11 // on-the-fly without requiring external
15 // This class is an extension and improvement of the public Domain
16 // FPDF class by Olivier Plathey (http://www.fpdf.org).
18 // Main changes by Nicola Asuni:
20 // UTF-8 Unicode support;
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 //============================================================+
33 * include configuration file
35 require_once(dirname(__FILE__
).'/config/tcpdf_config.php');
40 * @package com.tecnick.tcpdf
44 * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
45 * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
46 * <h3>TCPDF main changes from FPDF are:</h3><ul>
47 * <li>PHP4 porting</li>
48 * <li>UTF-8 Unicode support</li>
49 * <li>source code clean up</li>
50 * <li>code style and formatting</li>
51 * <li>source code documentation using phpDocumentor (www.phpdoc.org)</li>
52 * <li>All ISO page formats were included</li>
53 * <li>image scale factor</li>
54 * <li>includes methods to parse and printsome XHTML code, supporting the following elements: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small;</li>
55 * <li>includes a method to print various barcode formats using an improved version of "Generic Barcode Render Class" by Karim Mribti (http://www.mribti.com/barcode/) (require GD library: http://www.boutell.com/gd/)</li>
56 * <li>defines standard Header() and Footer() methods.</li>
58 * Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p>
60 * @package com.tecnick.tcpdf
61 * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
62 * @author Nicola Asuni
63 * @copyright 2004-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY - www.tecnick.com - info@tecnick.com
64 * @link http://tcpdf.sourceforge.net
65 * @license http://www.gnu.org/copyleft/lesser.html LGPL
66 @version 1.53.0.TC023_PHP4
69 if(!class_exists('TCPDF')) {
71 * define default PDF document producer
73 define('PDF_PRODUCER','TCPDF 1.53.0.TC023_PHP4 (http://tcpdf.sourceforge.net)');
76 * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
77 * This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
78 * 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>
79 * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
80 * To add your own TTF fonts please read /fonts/README.TXT
82 * @package com.tecnick.tcpdf
83 * @version 1.53.0.TC023
84 * @author Nicola Asuni
85 * @link http://tcpdf.sourceforge.net
86 * @license http://www.gnu.org/copyleft/lesser.html LGPL
92 * @var current page number
98 * @var current object number
104 * @var array of object offsets
110 * @var buffer holding in-memory PDF
116 * @var array containing pages
122 * @var current document state
128 * @var compression flag
134 * @var default orientation
140 * @var current orientation
146 * @var array indicating orientation changes
149 var $OrientationChanges;
152 * @var scale factor (number of points in user unit)
158 * @var width of page format in points
164 * @var height of page format in points
170 * @var width of page format in user unit
176 * @var height of page format in user unit
182 * @var current width of page in points
188 * @var current height of page in points
194 * @var current width of page in user unit
200 * @var current height of page in user unit
224 * @var page break margin
236 * @var current horizontal position in user unit for cell positioning
242 * @var current vertical position in user unit for cell positioning
248 * @var height of last cell printed
254 * @var line width in user unit
260 * @var array of standard font names
266 * @var array of used fonts
272 * @var array of font files
278 * @var array of encoding differences
284 * @var array of used images
290 * @var array of links in pages
296 * @var array of internal links
302 * @var current font family
308 * @var current font style
314 * @var underlining flag
320 * @var current font info
326 * @var current font size in points
332 * @var current font size in user unit
338 * @var commands for drawing color
344 * @var commands for filling color
350 * @var commands for text color
356 * @var indicates whether fill and text colors are different
368 * @var automatic page breaking
374 * @var threshold used to trigger page breaks
377 var $PageBreakTrigger;
380 * @var flag set when processing footer
386 * @var zoom display mode
392 * @var layout display mode
428 * @var alias for total number of pages
434 * @var right-bottom corner X coordinate of inserted image
436 * @author Nicola Asuni
442 * @var right-bottom corner Y coordinate of inserted image
444 * @author Nicola Asuni
450 * @var image scale factor
452 * @author Nicola Asuni
458 * @var boolean set to true when the input text is unicode (require unicode fonts)
460 * @author Nicola Asuni
463 var $isunicode = false;
470 var $PDFVersion = "1.3";
473 // ----------------------
476 * @var Minimum distance between header and top page margin.
482 * @var Minimum distance between footer and bottom page margin.
488 * @var original left margin value
490 * @since 1.53.0.TC013
492 var $original_lMargin;
495 * @var original right margin value
497 * @since 1.53.0.TC013
499 var $original_rMargin;
514 * @var Language templates.
520 * @var Barcode to print on page footer (only if set).
523 var $barcode = false;
526 * @var If true prints header
529 var $print_header = true;
532 * @var If true prints footer.
535 var $print_footer = true;
538 * @var Header width (0 = full page width).
541 var $header_width = 0;
544 * @var Header image logo.
547 var $header_logo = "";
550 * @var Header image logo width in mm.
553 var $header_logo_width = 30;
556 * @var String to print as title on document header.
559 var $header_title = "";
562 * @var String to print on document header.
565 var $header_string = "";
568 * @var Default number of columns for html table.
571 var $default_table_columns = 4;
574 // variables for html parser
577 * @var HTML PARSER: store current link.
583 * @var HTML PARSER: store font list.
589 * @var HTML PARSER: true when font attribute is set.
595 * @var HTML PARSER: true when color attribute is set.
601 * @var HTML PARSER: true in case of ordered list (OL), false otherwise.
604 var $listordered = false;
607 * @var HTML PARSER: count list items.
613 * @var HTML PARSER: size of table border.
616 var $tableborder = 0;
619 * @var HTML PARSER: true at the beginning of table.
622 var $tdbegin = false;
625 * @var HTML PARSER: table width.
631 * @var HTML PARSER: table height.
637 * @var HTML PARSER: table align.
643 * @var HTML PARSER: table background color.
646 var $tdbgcolor = false;
649 * @var Store temporary font size in points.
652 var $tempfontsize = 10;
655 * @var Bold font style status.
661 * @var Underlined font style status.
667 * @var Italic font style status.
673 * @var spacer for LI tags.
679 * @var default encoding
681 * @since 1.53.0.TC010
683 var $encoding = "UTF-8";
686 * @var PHP internal encoding
688 * @since 1.53.0.TC016
690 var $internal_encoding;
693 * @var store previous fill color as RGB array
695 * @since 1.53.0.TC017
697 var $prevFillColor = array(255,255,255);
700 * @var store previous text color as RGB array
702 * @since 1.53.0.TC017
704 var $prevTextColor = array(0,0,0);
707 * @var store previous font family
709 * @since 1.53.0.TC017
714 * @var store previous font style
716 * @since 1.53.0.TC017
720 //------------------------------------------------------------
722 //------------------------------------------------------------
725 * This is the class constructor.
726 * It allows to set up the page format, the orientation and
727 * the measure unit used in all the methods (except for the font sizes).
729 * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
730 * @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.
731 * @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>
732 * @param boolean $unicode TRUE means that the input text is unicode (default = true)
733 * @param String $encoding charset encoding; default is UTF-8
735 function TCPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding="UTF-8") {
737 /* Set internal character encoding to ASCII */
738 if (function_exists("mb_internal_encoding") AND mb_internal_encoding()) {
739 $this->internal_encoding
= mb_internal_encoding();
740 mb_internal_encoding("ASCII");
745 //Initialization of properties
746 $this->isunicode
=$unicode;
750 $this->pages
=array();
751 $this->OrientationChanges
=array();
753 $this->fonts
=array();
754 $this->FontFiles
=array();
755 $this->diffs
=array();
756 $this->images
=array();
757 $this->links
=array();
758 $this->InFooter
=false;
760 $this->FontFamily
='';
762 $this->FontSizePt
=12;
763 $this->underline
=false;
764 $this->DrawColor
='0 G';
765 $this->FillColor
='0 g';
766 $this->TextColor
='0 g';
767 $this->ColorFlag
=false;
769 //Standard Unicode fonts
770 $this->CoreFonts
=array(
771 'courier'=>'Courier',
772 'courierB'=>'Courier-Bold',
773 'courierI'=>'Courier-Oblique',
774 'courierBI'=>'Courier-BoldOblique',
775 'helvetica'=>'Helvetica',
776 'helveticaB'=>'Helvetica-Bold',
777 'helveticaI'=>'Helvetica-Oblique',
778 'helveticaBI'=>'Helvetica-BoldOblique',
779 'times'=>'Times-Roman',
780 'timesB'=>'Times-Bold',
781 'timesI'=>'Times-Italic',
782 'timesBI'=>'Times-BoldItalic',
784 'zapfdingbats'=>'ZapfDingbats'
788 // 2003-06-11 - Nicola Asuni : changed if/else with switch statement
789 switch (strtolower($unit)){
790 case 'pt': {$this->k
=1; break;}
791 case 'mm': {$this->k
=72/25.4; break;}
792 case 'cm': {$this->k
=72/2.54; break;}
793 case 'in': {$this->k
=72; break;}
794 default : {$this->Error('Incorrect unit: '.$unit); break;}
798 if(is_string($format)) {
799 // 2002-07-24 - Nicola Asuni (info@tecnick.com)
800 // Added new page formats (45 standard ISO paper formats and 4 american common formats).
801 // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
802 switch (strtoupper($format)){
803 case '4A0': {$format = array(4767.87,6740.79); break;}
804 case '2A0': {$format = array(3370.39,4767.87); break;}
805 case 'A0': {$format = array(2383.94,3370.39); break;}
806 case 'A1': {$format = array(1683.78,2383.94); break;}
807 case 'A2': {$format = array(1190.55,1683.78); break;}
808 case 'A3': {$format = array(841.89,1190.55); break;}
809 case 'A4': default: {$format = array(595.28,841.89); break;}
810 case 'A5': {$format = array(419.53,595.28); break;}
811 case 'A6': {$format = array(297.64,419.53); break;}
812 case 'A7': {$format = array(209.76,297.64); break;}
813 case 'A8': {$format = array(147.40,209.76); break;}
814 case 'A9': {$format = array(104.88,147.40); break;}
815 case 'A10': {$format = array(73.70,104.88); break;}
816 case 'B0': {$format = array(2834.65,4008.19); break;}
817 case 'B1': {$format = array(2004.09,2834.65); break;}
818 case 'B2': {$format = array(1417.32,2004.09); break;}
819 case 'B3': {$format = array(1000.63,1417.32); break;}
820 case 'B4': {$format = array(708.66,1000.63); break;}
821 case 'B5': {$format = array(498.90,708.66); break;}
822 case 'B6': {$format = array(354.33,498.90); break;}
823 case 'B7': {$format = array(249.45,354.33); break;}
824 case 'B8': {$format = array(175.75,249.45); break;}
825 case 'B9': {$format = array(124.72,175.75); break;}
826 case 'B10': {$format = array(87.87,124.72); break;}
827 case 'C0': {$format = array(2599.37,3676.54); break;}
828 case 'C1': {$format = array(1836.85,2599.37); break;}
829 case 'C2': {$format = array(1298.27,1836.85); break;}
830 case 'C3': {$format = array(918.43,1298.27); break;}
831 case 'C4': {$format = array(649.13,918.43); break;}
832 case 'C5': {$format = array(459.21,649.13); break;}
833 case 'C6': {$format = array(323.15,459.21); break;}
834 case 'C7': {$format = array(229.61,323.15); break;}
835 case 'C8': {$format = array(161.57,229.61); break;}
836 case 'C9': {$format = array(113.39,161.57); break;}
837 case 'C10': {$format = array(79.37,113.39); break;}
838 case 'RA0': {$format = array(2437.80,3458.27); break;}
839 case 'RA1': {$format = array(1729.13,2437.80); break;}
840 case 'RA2': {$format = array(1218.90,1729.13); break;}
841 case 'RA3': {$format = array(864.57,1218.90); break;}
842 case 'RA4': {$format = array(609.45,864.57); break;}
843 case 'SRA0': {$format = array(2551.18,3628.35); break;}
844 case 'SRA1': {$format = array(1814.17,2551.18); break;}
845 case 'SRA2': {$format = array(1275.59,1814.17); break;}
846 case 'SRA3': {$format = array(907.09,1275.59); break;}
847 case 'SRA4': {$format = array(637.80,907.09); break;}
848 case 'LETTER': {$format = array(612.00,792.00); break;}
849 case 'LEGAL': {$format = array(612.00,1008.00); break;}
850 case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
851 case 'FOLIO': {$format = array(612.00,936.00); break;}
852 // default: {$this->Error('Unknown page format: '.$format); break;}
853 // END CHANGES Nicola Asuni
855 $this->fwPt
=$format[0];
856 $this->fhPt
=$format[1];
859 $this->fwPt
=$format[0]*$this->k
;
860 $this->fhPt
=$format[1]*$this->k
;
863 $this->fw
=$this->fwPt
/$this->k
;
864 $this->fh
=$this->fhPt
/$this->k
;
867 $orientation=strtolower($orientation);
868 if($orientation=='p' or $orientation=='portrait') {
869 $this->DefOrientation
='P';
870 $this->wPt
=$this->fwPt
;
871 $this->hPt
=$this->fhPt
;
873 elseif($orientation=='l' or $orientation=='landscape') {
874 $this->DefOrientation
='L';
875 $this->wPt
=$this->fhPt
;
876 $this->hPt
=$this->fwPt
;
879 $this->Error('Incorrect orientation: '.$orientation);
882 $this->CurOrientation
=$this->DefOrientation
;
883 $this->w
=$this->wPt
/$this->k
;
884 $this->h
=$this->hPt
/$this->k
;
885 //Page margins (1 cm)
886 $margin=28.35/$this->k
;
887 $this->SetMargins($margin,$margin);
888 //Interior cell margin (1 mm)
889 $this->cMargin
=$margin/10;
890 //Line width (0.2 mm)
891 $this->LineWidth
=.567/$this->k
;
892 //Automatic page break
893 $this->SetAutoPageBreak(true,2*$margin);
894 //Full width display mode
895 $this->SetDisplayMode('fullwidth');
897 $this->SetCompression(true);
898 //Set default PDF version number
899 $this->PDFVersion
= "1.3";
901 $this->encoding
= $encoding;
906 $this->fontlist
= array("arial", "times", "courier", "helvetica", "symbol");
907 $this->issetfont
= false;
908 $this->issetcolor
= false;
909 $this->tableborder
= 0;
910 $this->tdbegin
= false;
913 $this->tdalign
= "L";
914 $this->tdbgcolor
= false;
916 $this->SetFillColor(200, 200, 200, true);
917 $this->SetTextColor(0, 0, 0, true);
921 * Set the image scale.
922 * @param float $scale image scale.
923 * @author Nicola Asuni
926 function setImageScale($scale) {
927 $this->imgscale
=$scale;
931 * Returns the image scale.
932 * @return float image scale.
933 * @author Nicola Asuni
936 function getImageScale() {
937 return $this->imgscale
;
941 * Returns the page width in units.
942 * @return int page width.
943 * @author Nicola Asuni
946 function getPageWidth() {
951 * Returns the page height in units.
952 * @return int page height.
953 * @author Nicola Asuni
956 function getPageHeight() {
961 * Returns the page break margin.
962 * @return int page break margin.
963 * @author Nicola Asuni
966 function getBreakMargin() {
967 return $this->bMargin
;
971 * Returns the scale factor (number of points in user unit).
972 * @return int scale factor.
973 * @author Nicola Asuni
976 function getScaleFactor() {
981 * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
982 * @param float $left Left margin.
983 * @param float $top Top margin.
984 * @param float $right Right margin. Default value is the left one.
986 * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
988 function SetMargins($left, $top, $right=-1) {
989 //Set left, top and right margins
990 $this->lMargin
=$left;
995 $this->rMargin
=$right;
999 * 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.
1000 * @param float $margin The margin.
1002 * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
1004 function SetLeftMargin($margin) {
1006 $this->lMargin
=$margin;
1007 if(($this->page
>0) and ($this->x
<$margin)) {
1013 * Defines the top margin. The method can be called before creating the first page.
1014 * @param float $margin The margin.
1016 * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
1018 function SetTopMargin($margin) {
1020 $this->tMargin
=$margin;
1024 * Defines the right margin. The method can be called before creating the first page.
1025 * @param float $margin The margin.
1027 * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
1029 function SetRightMargin($margin) {
1031 $this->rMargin
=$margin;
1035 * 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.
1036 * @param boolean $auto Boolean indicating if mode should be on or off.
1037 * @param float $margin Distance from the bottom of the page.
1039 * @see Cell(), MultiCell(), AcceptPageBreak()
1041 function SetAutoPageBreak($auto, $margin=0) {
1042 //Set auto page break mode and triggering margin
1043 $this->AutoPageBreak
=$auto;
1044 $this->bMargin
=$margin;
1045 $this->PageBreakTrigger
=$this->h
-$margin;
1049 * 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.
1050 * @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>
1051 * @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>
1054 function SetDisplayMode($zoom, $layout='continuous') {
1055 //Set display mode in viewer
1056 if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
1057 $this->ZoomMode
=$zoom;
1060 $this->Error('Incorrect zoom display mode: '.$zoom);
1062 if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') {
1063 $this->LayoutMode
=$layout;
1066 $this->Error('Incorrect layout display mode: '.$layout);
1071 * 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.
1072 * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
1073 * @param boolean $compress Boolean indicating if compression must be enabled.
1076 function SetCompression($compress) {
1077 //Set page compression
1078 if(function_exists('gzcompress')) {
1079 $this->compress
=$compress;
1082 $this->compress
=false;
1087 * Defines the title of the document.
1088 * @param string $title The title.
1090 * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
1092 function SetTitle($title) {
1094 $this->title
=$title;
1098 * Defines the subject of the document.
1099 * @param string $subject The subject.
1101 * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
1103 function SetSubject($subject) {
1104 //Subject of document
1105 $this->subject
=$subject;
1109 * Defines the author of the document.
1110 * @param string $author The name of the author.
1112 * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
1114 function SetAuthor($author) {
1115 //Author of document
1116 $this->author
=$author;
1120 * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
1121 * @param string $keywords The list of keywords.
1123 * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
1125 function SetKeywords($keywords) {
1126 //Keywords of document
1127 $this->keywords
=$keywords;
1131 * Defines the creator of the document. This is typically the name of the application that generates the PDF.
1132 * @param string $creator The name of the creator.
1134 * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
1136 function SetCreator($creator) {
1137 //Creator of document
1138 $this->creator
=$creator;
1142 * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
1143 * <b>Example:</b><br />
1145 * class PDF extends TCPDF {
1146 * function Footer() {
1147 * //Go to 1.5 cm from bottom
1149 * //Select Arial italic 8
1150 * $this->SetFont('Arial','I',8);
1151 * //Print current and total page numbers
1152 * $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
1156 * $pdf->AliasNbPages();
1158 * @param string $alias The alias. Default value: {nb}.
1160 * @see PageNo(), Footer()
1162 function AliasNbPages($alias='{nb}') {
1163 //Define an alias for total number of pages
1164 $this->AliasNbPages
= $this->_escapetext($alias);
1168 * 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.
1169 * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
1170 * @param string $msg The error message
1173 function Error($msg) {
1175 die('<strong>TCPDF error: </strong>'.$msg);
1179 * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
1180 * Note: no page is created by this method
1182 * @see AddPage(), Close()
1190 * Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document.
1192 * @see Open(), Output()
1195 //Terminate document
1196 if($this->state
==3) {
1199 if($this->page
==0) {
1203 $this->InFooter
=true;
1205 $this->InFooter
=false;
1213 * 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.
1214 * 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.
1215 * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
1216 * @param string $orientation Page orientation. Possible values are (case insensitive):<ul><li>P or Portrait</li><li>L or Landscape</li></ul> The default value is the one passed to the constructor.
1218 * @see TCPDF(), Header(), Footer(), SetMargins()
1220 function AddPage($orientation='') {
1222 if($this->state
==0) {
1225 $family=$this->FontFamily
;
1226 $style=$this->FontStyle
.($this->underline ?
'U' : '');
1227 $size=$this->FontSizePt
;
1228 $lw=$this->LineWidth
;
1229 $dc=$this->DrawColor
;
1230 $fc=$this->FillColor
;
1231 $tc=$this->TextColor
;
1232 $cf=$this->ColorFlag
;
1235 $this->InFooter
=true;
1237 $this->InFooter
=false;
1242 $this->_beginpage($orientation);
1243 //Set line cap style to square
1246 $this->LineWidth
=$lw;
1247 $this->_out(sprintf('%.2f w',$lw*$this->k
));
1250 $this->SetFont($family,$style,$size);
1253 $this->DrawColor
=$dc;
1257 $this->FillColor
=$fc;
1261 $this->TextColor
=$tc;
1262 $this->ColorFlag
=$cf;
1265 //Restore line width
1266 if($this->LineWidth
!=$lw) {
1267 $this->LineWidth
=$lw;
1268 $this->_out(sprintf('%.2f w',$lw*$this->k
));
1272 $this->SetFont($family,$style,$size);
1275 if($this->DrawColor
!=$dc) {
1276 $this->DrawColor
=$dc;
1279 if($this->FillColor
!=$fc) {
1280 $this->FillColor
=$fc;
1283 $this->TextColor
=$tc;
1284 $this->ColorFlag
=$cf;
1291 * @param string $ln header image logo
1292 * @param string $lw header image logo width in mm
1293 * @param string $ht string to print as title on document header
1294 * @param string $hs string to print on document header
1296 function setHeaderData($ln="", $lw=0, $ht="", $hs="") {
1297 $this->header_logo
= $ln;
1298 $this->header_logo_width
= $lw;
1299 $this->header_title
= $ht;
1300 $this->header_string
= $hs;
1304 * Set header margin.
1305 * (minimum distance between header and top page margin)
1306 * @param int $hm distance in millimeters
1308 function setHeaderMargin($hm=10) {
1309 $this->header_margin
= $hm;
1313 * Set footer margin.
1314 * (minimum distance between footer and bottom page margin)
1315 * @param int $fm distance in millimeters
1317 function setFooterMargin($fm=10) {
1318 $this->footer_margin
= $fm;
1322 * This method is used to render the page header.
1323 * It is automatically called by AddPage() and could be overwritten in your own inherited class.
1326 if ($this->print_header
) {
1328 if (!isset($this->original_lMargin
)) {
1329 $this->original_lMargin
= $this->lMargin
;
1331 if (!isset($this->original_rMargin
)) {
1332 $this->original_rMargin
= $this->rMargin
;
1335 //set current position
1336 $this->SetXY($this->original_lMargin
, $this->header_margin
);
1338 if (($this->header_logo
) AND ($this->header_logo
!= K_BLANK_IMAGE
)) {
1339 $this->Image(K_PATH_IMAGES
.$this->header_logo
, $this->original_lMargin
, $this->header_margin
, $this->header_logo_width
);
1342 $this->img_rb_y
= $this->GetY();
1345 $cell_height = round((K_CELL_HEIGHT_RATIO
* $this->header_font
[2]) / $this->k
, 2);
1347 $header_x = $this->original_lMargin +
($this->header_logo_width
* 1.05); //set left margin for text data cell
1350 $this->SetFont($this->header_font
[0], 'B', $this->header_font
[2] +
1);
1351 $this->SetX($header_x);
1352 $this->Cell($this->header_width
, $cell_height, $this->header_title
, 0, 1, 'L');
1355 $this->SetFont($this->header_font
[0], $this->header_font
[1], $this->header_font
[2]);
1356 $this->SetX($header_x);
1357 $this->MultiCell($this->header_width
, $cell_height, $this->header_string
, 0, 'L', 0);
1359 // print an ending header line
1360 if (empty($this->header_width
)) {
1361 //set style for cell border
1362 $this->SetLineWidth(0.3);
1363 $this->SetDrawColor(0, 0, 0);
1364 $this->SetY(1 +
max($this->img_rb_y
, $this->GetY()));
1365 $this->SetX($this->original_lMargin
);
1366 $this->Cell(0, 0, '', 'T', 0, 'C');
1370 $this->SetXY($this->original_lMargin
, $this->tMargin
);
1375 * This method is used to render the page footer.
1376 * It is automatically called by AddPage() and could be overwritten in your own inherited class.
1379 if ($this->print_footer
) {
1381 if (!isset($this->original_lMargin
)) {
1382 $this->original_lMargin
= $this->lMargin
;
1384 if (!isset($this->original_rMargin
)) {
1385 $this->original_rMargin
= $this->rMargin
;
1389 $this->SetFont($this->footer_font
[0], $this->footer_font
[1] , $this->footer_font
[2]);
1390 //set style for cell border
1392 $this->SetLineWidth($line_width);
1393 $this->SetDrawColor(0, 0, 0);
1395 $footer_height = round((K_CELL_HEIGHT_RATIO
* $this->footer_font
[2]) / $this->k
, 2); //footer height
1396 //get footer y position
1397 $footer_y = $this->h
- $this->footer_margin
- $footer_height;
1398 //set current position
1399 $this->SetXY($this->original_lMargin
, $footer_y);
1401 //print document barcode
1402 if ($this->barcode
) {
1404 $barcode_width = round(($this->w
- $this->original_lMargin
- $this->original_rMargin
)); //max width
1405 $this->writeBarcode($this->original_lMargin
, $footer_y +
$line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode
);
1408 $this->SetXY($this->original_lMargin
, $footer_y);
1411 $this->Cell(0, $footer_height, $this->l
['w_page']." ".$this->PageNo().' / {nb}', 'T', 0, 'R');
1416 * Returns the current page number.
1417 * @return int page number
1419 * @see AliasNbPages()
1422 //Get current page number
1427 * 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.
1428 * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1429 * @param int $g Green component (between 0 and 255)
1430 * @param int $b Blue component (between 0 and 255)
1432 * @see SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
1434 function SetDrawColor($r, $g=-1, $b=-1) {
1435 //Set color for all stroking operations
1436 if(($r==0 and $g==0 and $b==0) or $g==-1) {
1437 $this->DrawColor
=sprintf('%.3f G',$r/255);
1440 $this->DrawColor
=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
1443 $this->_out($this->DrawColor
);
1448 * 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.
1449 * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1450 * @param int $g Green component (between 0 and 255)
1451 * @param int $b Blue component (between 0 and 255)
1452 * @param boolean $storeprev if true stores the RGB array on $prevFillColor variable.
1454 * @see SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
1456 function SetFillColor($r, $g=-1, $b=-1, $storeprev=false) {
1457 //Set color for all filling operations
1458 if(($r==0 and $g==0 and $b==0) or $g==-1) {
1459 $this->FillColor
=sprintf('%.3f g',$r/255);
1462 $this->FillColor
=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
1464 $this->ColorFlag
=($this->FillColor
!=$this->TextColor
);
1466 $this->_out($this->FillColor
);
1469 // store color as previous value
1470 $this->prevFillColor
= array($r, $g, $b);
1475 * 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.
1476 * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1477 * @param int $g Green component (between 0 and 255)
1478 * @param int $b Blue component (between 0 and 255)
1479 * @param boolean $storeprev if true stores the RGB array on $prevTextColor variable.
1481 * @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
1483 function SetTextColor($r, $g=-1, $b=-1, $storeprev=false) {
1484 //Set color for text
1485 if(($r==0 and $g==0 and $b==0) or $g==-1) {
1486 $this->TextColor
=sprintf('%.3f g',$r/255);
1489 $this->TextColor
=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
1491 $this->ColorFlag
=($this->FillColor
!=$this->TextColor
);
1493 // store color as previous value
1494 $this->prevTextColor
= array($r, $g, $b);
1499 * Returns the length of a string in user unit. A font must be selected.<br>
1500 * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]
1501 * @param string $s The string whose length is to be computed
1505 function GetStringWidth($s) {
1506 //Get width of a string in the current font
1508 $cw = &$this->CurrentFont
['cw'];
1510 if($this->isunicode
) {
1511 $unicode = $this->UTF8StringToArray($s);
1512 foreach($unicode as $char) {
1513 if (isset($cw[$char])) {
1515 } elseif(isset($cw[ord($char)])) {
1516 $w+
=$cw[ord($char)];
1517 } elseif(isset($cw[chr($char)])) {
1518 $w+
=$cw[chr($char)];
1519 } elseif(isset($this->CurrentFont
['desc']['MissingWidth'])) {
1520 $w +
= $this->CurrentFont
['desc']['MissingWidth']; // set default size
1527 for($i=0; $i<$l; $i++
) {
1528 if (isset($cw[$s{$i}])) {
1530 } else if (isset($cw[ord($s{$i})])) {
1531 $w +
= $cw[ord($s{$i})];
1535 return ($w * $this->FontSize
/ 1000);
1539 * 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.
1540 * @param float $width The width.
1542 * @see Line(), Rect(), Cell(), MultiCell()
1544 function SetLineWidth($width) {
1546 $this->LineWidth
=$width;
1548 $this->_out(sprintf('%.2f w',$width*$this->k
));
1553 * Draws a line between two points.
1554 * @param float $x1 Abscissa of first point
1555 * @param float $y1 Ordinate of first point
1556 * @param float $x2 Abscissa of second point
1557 * @param float $y2 Ordinate of second point
1559 * @see SetLineWidth(), SetDrawColor()
1561 function Line($x1, $y1, $x2, $y2) {
1563 $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
));
1567 * Outputs a rectangle. It can be drawn (border only), filled (with no border) or both.
1568 * @param float $x Abscissa of upper-left corner
1569 * @param float $y Ordinate of upper-left corner
1570 * @param float $w Width
1571 * @param float $h Height
1572 * @param string $style Style of rendering. Possible values are:<ul><li>D or empty string: draw (default)</li><li>F: fill</li><li>DF or FD: draw and fill</li></ul>
1574 * @see SetLineWidth(), SetDrawColor(), SetFillColor()
1576 function Rect($x, $y, $w, $h, $style='') {
1581 elseif($style=='FD' or $style=='DF') {
1587 $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k
,($this->h
-$y)*$this->k
,$w*$this->k
,-$h*$this->k
,$op));
1591 * 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.
1592 * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02].
1593 * <b>Example</b>:<br />
1595 * $pdf->AddFont('Comic','I');
1596 * // is equivalent to:
1597 * $pdf->AddFont('Comic','I','comici.php');
1599 * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
1600 * @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>
1601 * @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no space.
1605 function AddFont($family, $style='', $file='') {
1606 if(empty($family)) {
1610 //Add a TrueType or Type1 font
1611 $family = strtolower($family);
1612 if((!$this->isunicode
) AND ($family == 'arial')) {
1613 $family = 'helvetica';
1616 $style=strtoupper($style);
1617 $style=str_replace('U','',$style);
1618 if($style == 'IB') {
1622 $fontkey = $family.$style;
1623 // check if the font has been already added
1624 if(isset($this->fonts
[$fontkey])) {
1629 $file = str_replace(' ', '', $family).strtolower($style).'.php';
1631 if(!file_exists($this->_getfontpath().$file)) {
1632 // try to load the basic file without styles
1633 $file = str_replace(' ', '', $family).'.php';
1636 include($this->_getfontpath().$file);
1638 if(!isset($name) AND !isset($fpdf_charwidths)) {
1639 $this->Error('Could not include font definition file');
1642 $i = count($this->fonts
)+
1;
1644 if($this->isunicode
) {
1645 $this->fonts
[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg);
1646 $fpdf_charwidths[$fontkey] = $cw;
1648 $this->fonts
[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts
[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]);
1651 if(isset($diff) AND (!empty($diff))) {
1652 //Search existing encodings
1654 $nb=count($this->diffs
);
1655 for($i=1;$i<=$nb;$i++
) {
1656 if($this->diffs
[$i]==$diff) {
1663 $this->diffs
[$d]=$diff;
1665 $this->fonts
[$fontkey]['diff']=$d;
1668 if((strcasecmp($type,"TrueType") == 0) OR (strcasecmp($type,"TrueTypeUnicode") == 0)) {
1669 $this->FontFiles
[$file]=array('length1'=>$originalsize);
1672 $this->FontFiles
[$file]=array('length1'=>$size1,'length2'=>$size2);
1678 * 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.
1679 * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
1680 * The method can be called before the first page is created and the font is retained from page to page.
1681 If you just wish to change the current font size, it is simpler to call SetFontSize().
1682 * 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 />
1683 * Example for the last case (note the trailing slash):<br />
1685 * define('FPDF_FONTPATH','/home/www/font/');
1686 * require('tcpdf.php');
1688 * //Times regular 12
1689 * $pdf->SetFont('Times');
1691 * $pdf->SetFont('Arial','B',14);
1693 * $pdf->SetFont('');
1694 * //Times bold, italic and underlined 14
1695 * $pdf->SetFont('Times','BIU');
1697 * If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated.
1698 * @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.
1699 * @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
1700 * @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
1702 * @see AddFont(), SetFontSize(), Cell(), MultiCell(), Write()
1704 function SetFont($family, $style='', $size=0) {
1705 // save previous values
1706 $this->prevFontFamily
= $this->FontFamily
;
1707 $this->prevFontStyle
= $this->FontStyle
;
1709 //Select a font; size given in points
1710 global $fpdf_charwidths;
1712 $family=strtolower($family);
1714 $family=$this->FontFamily
;
1716 if((!$this->isunicode
) AND ($family == 'arial')) {
1717 $family = 'helvetica';
1719 elseif(($family=="symbol") OR ($family=="zapfdingbats")) {
1722 $style=strtoupper($style);
1724 if(strpos($style,'U')!==false) {
1725 $this->underline
=true;
1726 $style=str_replace('U','',$style);
1729 $this->underline
=false;
1735 $size=$this->FontSizePt
;
1738 // try to add font (if not already added)
1739 if($this->isunicode
) {
1740 $this->AddFont($family, $style);
1743 //Test if font is already selected
1744 if(($this->FontFamily
== $family) AND ($this->FontStyle
== $style) AND ($this->FontSizePt
== $size)) {
1748 $fontkey = $family.$style;
1749 //if(!isset($this->fonts[$fontkey]) AND isset($this->fonts[$family])) {
1753 //Test if used for the first time
1754 if(!isset($this->fonts
[$fontkey])) {
1755 //Check if one of the standard fonts
1756 if(isset($this->CoreFonts
[$fontkey])) {
1757 if(!isset($fpdf_charwidths[$fontkey])) {
1760 if(($family!='symbol') AND ($family!='zapfdingbats')) {
1761 $file .= strtolower($style);
1763 if(!file_exists($this->_getfontpath().$file.'.php')) {
1764 // try to load the basic file without styles
1768 include($this->_getfontpath().$file.'.php');
1769 if (($this->isunicode
AND !isset($ctg)) OR ((!$this->isunicode
) AND (!isset($fpdf_charwidths[$fontkey]))) ) {
1770 $this->Error("Could not include font metric file [".$fontkey."]: ".$this->_getfontpath().$file.".php");
1773 $i = count($this->fonts
) +
1;
1775 if($this->isunicode
) {
1776 $this->fonts
[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg);
1777 $fpdf_charwidths[$fontkey] = $cw;
1779 $this->fonts
[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts
[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]);
1783 $this->Error('Undefined font: '.$family.' '.$style);
1787 $this->FontFamily
= $family;
1788 $this->FontStyle
= $style;
1789 $this->FontSizePt
= $size;
1790 $this->FontSize
= $size / $this->k
;
1791 $this->CurrentFont
= &$this->fonts
[$fontkey];
1793 $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont
['i'], $this->FontSizePt
));
1798 * Defines the size of the current font.
1799 * @param float $size The size (in points)
1803 function SetFontSize($size) {
1804 //Set font size in points
1805 if($this->FontSizePt
==$size) {
1808 $this->FontSizePt
= $size;
1809 $this->FontSize
= $size / $this->k
;
1810 if($this->page
> 0) {
1811 $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont
['i'], $this->FontSizePt
));
1816 * 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 />
1817 * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
1819 * @see Cell(), Write(), Image(), Link(), SetLink()
1821 function AddLink() {
1822 //Create a new internal link
1823 $n=count($this->links
)+
1;
1824 $this->links
[$n]=array(0,0);
1829 * Defines the page and position a link points to
1830 * @param int $link The link identifier returned by AddLink()
1831 * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
1832 * @param int $page Number of target page; -1 indicates the current page. This is the default value
1836 function SetLink($link, $y=0, $page=-1) {
1837 //Set destination of internal link
1844 $this->links
[$link]=array($page,$y);
1848 * 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.
1849 * @param float $x Abscissa of the upper-left corner of the rectangle
1850 * @param float $y Ordinate of the upper-left corner of the rectangle
1851 * @param float $w Width of the rectangle
1852 * @param float $h Height of the rectangle
1853 * @param mixed $link URL or identifier returned by AddLink()
1855 * @see AddLink(), Cell(), Write(), Image()
1857 function Link($x, $y, $w, $h, $link) {
1858 //Put a link on the page
1859 $this->PageLinks
[$this->page
][] = array($x * $this->k
, $this->hPt
- $y * $this->k
, $w * $this->k
, $h*$this->k
, $link);
1863 * 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.
1864 * @param float $x Abscissa of the origin
1865 * @param float $y Ordinate of the origin
1866 * @param string $txt String to print
1868 * @see SetFont(), SetTextColor(), Cell(), MultiCell(), Write()
1870 function Text($x, $y, $txt) {
1872 $s=sprintf('BT %.2f %.2f Td (%s) Tj ET', $x * $this->k
, ($this->h
-$y) * $this->k
, $this->_escapetext($txt));
1873 if($this->underline
AND ($txt!='')) {
1874 $s .= ' '.$this->_dounderline($x,$y,$txt);
1876 if($this->ColorFlag
) {
1877 $s='q '.$this->TextColor
.' '.$s.' Q';
1883 * 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 />
1884 * This method is called automatically and should not be called directly by the application.<br />
1885 * <b>Example:</b><br />
1886 * The method is overriden in an inherited class in order to obtain a 3 column layout:<br />
1888 * class PDF extends TCPDF {
1891 * function SetCol($col) {
1892 * //Move position to a column
1895 * $this->SetLeftMargin($x);
1899 * function AcceptPageBreak() {
1900 * if($this->col<2) {
1901 * //Go to next column
1902 * $this->SetCol($this->col+1);
1907 * //Go back to first column and issue page break
1917 * $pdf->SetFont('Arial','',12);
1918 * for($i=1;$i<=300;$i++) {
1919 * $pdf->Cell(0,5,"Line $i",0,1);
1925 * @see SetAutoPageBreak()
1927 function AcceptPageBreak() {
1928 //Accept automatic page break or not
1929 return $this->AutoPageBreak
;
1933 * 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 />
1934 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
1935 * @param float $w Cell width. If 0, the cell extends up to the right margin.
1936 * @param float $h Cell height. Default value: 0.
1937 * @param string $txt String to print. Default value: empty string.
1938 * @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>
1939 * @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>
1940 Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
1941 * @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>
1942 * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1943 * @param mixed $link URL or identifier returned by AddLink().
1945 * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
1947 function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='') {
1950 if(($this->y +
$h) > $this->PageBreakTrigger
AND empty($this->InFooter
) AND $this->AcceptPageBreak()) {
1951 //Automatic page break
1956 $this->_out('0 Tw');
1958 $this->AddPage($this->CurOrientation
);
1962 $this->_out(sprintf('%.3f Tw',$ws * $k));
1966 $w = $this->w
- $this->rMargin
- $this->x
;
1969 if(($fill == 1) OR ($border == 1)) {
1971 $op = ($border == 1) ?
'B' : 'f';
1976 $s = sprintf('%.2f %.2f %.2f %.2f re %s ', $this->x
* $k, ($this->h
- $this->y
) * $k, $w * $k, -$h * $k, $op);
1978 if(is_string($border)) {
1981 if(strpos($border,'L')!==false) {
1982 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h
-$y)*$k,$x*$k,($this->h
-($y+
$h))*$k);
1984 if(strpos($border,'T')!==false) {
1985 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h
-$y)*$k,($x+
$w)*$k,($this->h
-$y)*$k);
1987 if(strpos($border,'R')!==false) {
1988 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+
$w)*$k,($this->h
-$y)*$k,($x+
$w)*$k,($this->h
-($y+
$h))*$k);
1990 if(strpos($border,'B')!==false) {
1991 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h
-($y+
$h))*$k,($x+
$w)*$k,($this->h
-($y+
$h))*$k);
1995 $width = $this->GetStringWidth($txt);
1997 $dx = $w - $this->cMargin
- $width;
1999 elseif($align=='C') {
2000 $dx = ($w - $width)/2;
2003 $dx = $this->cMargin
;
2005 if($this->ColorFlag
) {
2006 $s .= 'q '.$this->TextColor
.' ';
2008 $txt2 = $this->_escapetext($txt);
2009 $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);
2010 if($this->underline
) {
2011 $s.=' '.$this->_dounderline($this->x +
$dx, $this->y +
0.5 * $h +
0.3 * $this->FontSize
, $txt);
2013 if($this->ColorFlag
) {
2017 $this->Link($this->x +
$dx, $this->y +
0.5 * $h - 0.5 * $this->FontSize
, $width, $this->FontSize
, $link);
2028 $this->x
= $this->lMargin
;
2037 * 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 />
2038 * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
2039 * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
2040 * @param float $h Height of cells.
2041 * @param string $txt String to print
2042 * @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>
2043 * @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>
2044 Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
2045 * @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>
2046 * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
2048 * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
2050 function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0) {
2051 //Output text with automatic or explicit line breaks
2052 $cw = &$this->CurrentFont
['cw'];
2055 $w = $this->w
- $this->rMargin
- $this->x
;
2058 $wmax = ($w - 2 * $this->cMargin
);
2060 $s = str_replace("\r", '', $txt); // remove carriage returns
2072 if(strpos($border,'L')!==false) {
2075 if(strpos($border,'R')!==false) {
2078 $b=(strpos($border,'T')!==false) ?
$b2.'T' : $b2;
2088 //Get next character
2090 if(preg_match("/[\n]/u", $c)) {
2091 //Explicit line break
2094 $this->_out('0 Tw');
2096 $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
2103 if($border and $nl==2) {
2108 if(preg_match("/[ ]/u", $c)) {
2114 $l = $this->GetStringWidth(substr($s, $j, $i-$j));
2117 //Automatic line break
2124 $this->_out('0 Tw');
2126 $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
2130 $this->ws
= ($ns>1) ?
($wmax-$ls)/($ns-1) : 0;
2131 $this->_out(sprintf('%.3f Tw', $this->ws
* $this->k
));
2133 $this->Cell($w, $h, substr($s, $j, $sep-$j), $b, 2, $align, $fill);
2141 if($border AND ($nl==2)) {
2152 $this->_out('0 Tw');
2154 if($border and is_int(strpos($border,'B'))) {
2157 $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
2158 $this->x
=$this->lMargin
;
2162 * 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 />
2163 * <b>Example:</b><br />
2165 * //Begin with regular font
2166 * $pdf->SetFont('Arial','',14);
2167 * $pdf->Write(5,'Visit ');
2168 * //Then put a blue underlined link
2169 * $pdf->SetTextColor(0,0,255);
2170 * $pdf->SetFont('','U');
2171 * $pdf->Write(5,'www.tecnick.com','http://www.tecnick.com');
2173 * @param float $h Line height
2174 * @param string $txt String to print
2175 * @param mixed $link URL or identifier returned by AddLink()
2176 * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
2178 * @see SetFont(), SetTextColor(), AddLink(), MultiCell(), SetAutoPageBreak()
2180 function Write($h, $txt, $link='', $fill=0) {
2182 //Output text in flowing mode
2183 $cw = &$this->CurrentFont
['cw'];
2184 $w = $this->w
- $this->rMargin
- $this->x
;
2185 $wmax = ($w - 2 * $this->cMargin
);
2187 $s = str_replace("\r", '', $txt);
2190 // handle single space character
2191 if(($nb==1) AND preg_match("/[ ]/u", $s)) {
2192 $this->x +
= $this->GetStringWidth($s);
2202 //Get next character
2204 if(preg_match("/[\n]/u", $c)) {
2205 //Explicit line break
2206 $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link);
2212 $this->x
= $this->lMargin
;
2213 $w = $this->w
- $this->rMargin
- $this->x
;
2214 $wmax = ($w - 2 * $this->cMargin
);
2219 if(preg_match("/[ ]/u", $c)) {
2223 $l = $this->GetStringWidth(substr($s, $j, $i-$j));
2226 //Automatic line break (word wrapping)
2228 if($this->x
> $this->lMargin
) {
2230 $this->x
= $this->lMargin
;
2232 $w=$this->w
- $this->rMargin
- $this->x
;
2233 $wmax=($w - 2 * $this->cMargin
);
2241 $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link);
2244 $this->Cell($w, $h, substr($s, $j, $sep-$j), 0, 2, '', $fill, $link);
2251 $this->x
= $this->lMargin
;
2252 $w = $this->w
- $this->rMargin
- $this->x
;
2253 $wmax = ($w - 2 * $this->cMargin
);
2264 $this->Cell($this->GetStringWidth(substr($s, $j)." "), $h, substr($s, $j), 0, 0, '', $fill, $link);
2269 * 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>
2270 * Supported formats are JPEG and PNG.
2271 * For JPEG, all flavors are allowed:<ul><li>gray scales</li><li>true colors (24 bits)</li><li>CMYK (32 bits)</li></ul>
2272 * 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>
2273 * but are not supported:<ul><li>Interlacing</li><li>Alpha channel</li></ul>
2274 * If a transparent color is defined, it will be taken into account (but will be only interpreted by Acrobat 4 and above).<br />
2275 * The format can be specified explicitly or inferred from the file extension.<br />
2276 * It is possible to put a link on the image.<br />
2277 * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
2278 * @param string $file Name of the file containing the image.
2279 * @param float $x Abscissa of the upper-left corner.
2280 * @param float $y Ordinate of the upper-left corner.
2281 * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
2282 * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
2283 * @param string $type Image format. Possible values are (case insensitive): JPG, JPEG, PNG. If not specified, the type is inferred from the file extension.
2284 * @param mixed $link URL or identifier returned by AddLink().
2288 function Image($file, $x, $y, $w=0, $h=0, $type='', $link='') {
2289 //Put an image on the page
2290 if(!isset($this->images
[$file])) {
2291 //First use of image, get info
2293 $pos = strrpos($file,'.');
2295 $this->Error('Image file has no extension and no type was specified: '.$file);
2297 $type = substr($file, $pos+
1);
2299 $type = strtolower($type);
2300 $mqr = get_magic_quotes_runtime();
2301 set_magic_quotes_runtime(0);
2302 if($type == 'jpg' or $type == 'jpeg') {
2303 $info=$this->_parsejpg($file);
2305 elseif($type == 'png') {
2306 $info=$this->_parsepng($file);
2309 //Allow for additional formats
2310 $mtd='_parse'.$type;
2311 if(!method_exists($this,$mtd)) {
2312 $this->Error('Unsupported image type: '.$type);
2314 $info=$this->$mtd($file);
2316 set_magic_quotes_runtime($mqr);
2317 $info['i']=count($this->images
)+
1;
2318 $this->images
[$file]=$info;
2321 $info=$this->images
[$file];
2323 //Automatic width and height calculation if needed
2324 if(($w == 0) and ($h == 0)) {
2325 //Put image at 72 dpi
2326 // 2004-06-14 :: Nicola Asuni, scale factor where added
2327 $w = $info['w'] / ($this->imgscale
* $this->k
);
2328 $h = $info['h'] / ($this->imgscale
* $this->k
);
2331 $w = $h * $info['w'] / $info['h'];
2334 $h = $w * $info['h'] / $info['w'];
2336 $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']));
2338 $this->Link($x, $y, $w, $h, $link);
2341 //2002-07-31 - Nicola Asuni
2342 // set right-bottom corner coordinates
2343 $this->img_rb_x
= $x +
$w;
2344 $this->img_rb_y
= $y +
$h;
2348 * Performs a line break. The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
2349 * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
2353 function Ln($h='') {
2354 //Line feed; default value is last cell height
2355 $this->x
=$this->lMargin
;
2357 $this->y+
=$this->lasth
;
2365 * Returns the abscissa of the current position.
2368 * @see SetX(), GetY(), SetY()
2376 * Defines the abscissa of the current position. If the passed value is negative, it is relative to the right of the page.
2377 * @param float $x The value of the abscissa.
2379 * @see GetX(), GetY(), SetY(), SetXY()
2387 $this->x
=$this->w+
$x;
2392 * Returns the ordinate of the current position.
2395 * @see SetY(), GetX(), SetX()
2403 * 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.
2404 * @param float $y The value of the ordinate.
2406 * @see GetX(), GetY(), SetY(), SetXY()
2409 //Set y position and reset x
2410 $this->x
=$this->lMargin
;
2415 $this->y
=$this->h+
$y;
2420 * 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.
2421 * @param float $x The value of the abscissa
2422 * @param float $y The value of the ordinate
2424 * @see SetX(), SetY()
2426 function SetXY($x, $y) {
2427 //Set x and y positions
2433 * 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 />
2434 * The method first calls Close() if necessary to terminate the document.
2435 * @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.
2436 * @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).
2440 function Output($name='',$dest='') {
2441 //Output PDF to some destination
2442 //Finish document if necessary
2443 if($this->state
< 3) {
2446 //Normalize parameters
2447 if(is_bool($dest)) {
2448 $dest=$dest ?
'D' : 'F';
2450 $dest=strtoupper($dest);
2461 //Send to standard output
2462 if(ob_get_contents()) {
2463 $this->Error('Some data has already been output, can\'t send PDF file');
2465 if(php_sapi_name()!='cli') {
2466 //We send to a browser
2467 header('Content-Type: application/pdf');
2468 if(headers_sent()) {
2469 $this->Error('Some data has already been output to browser, can\'t send PDF file');
2471 header('Content-Length: '.strlen($this->buffer
));
2472 header('Content-disposition: inline; filename="'.$name.'"');
2479 if(ob_get_contents()) {
2480 $this->Error('Some data has already been output, can\'t send PDF file');
2482 if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) {
2483 header('Content-Type: application/force-download');
2485 header('Content-Type: application/octet-stream');
2487 if(headers_sent()) {
2488 $this->Error('Some data has already been output to browser, can\'t send PDF file');
2490 header('Content-Length: '.strlen($this->buffer
));
2491 header('Content-disposition: attachment; filename="'.$name.'"');
2496 //Save to local file
2497 $f=fopen($name,'wb');
2499 $this->Error('Unable to create output file: '.$name);
2501 fwrite($f,$this->buffer
,strlen($this->buffer
));
2506 //Return as a string
2507 return $this->buffer
;
2510 $this->Error('Incorrect output destination: '.$dest);
2519 * Check for locale-related bug
2522 function _dochecks() {
2523 //Check for locale-related bug
2525 $this->Error('Don\'t alter the locale before including class file');
2527 //Check for decimal separator
2528 if(sprintf('%.1f',1.0)!='1.0') {
2529 setlocale(LC_NUMERIC
,'C');
2537 function _getfontpath() {
2538 if(!defined('FPDF_FONTPATH') AND is_dir(dirname(__FILE__
).'/font')) {
2539 define('FPDF_FONTPATH', dirname(__FILE__
).'/font/');
2541 return defined('FPDF_FONTPATH') ? FPDF_FONTPATH
: '';
2548 function _begindoc() {
2551 $this->_out('%PDF-1.3');
2558 function _putpages() {
2560 if(!empty($this->AliasNbPages
)) {
2561 $nbstr = $this->UTF8ToUTF16BE($nb, false);
2562 //Replace number of pages
2563 for($n=1;$n<=$nb;$n++
) {
2564 $this->pages
[$n]=str_replace($this->AliasNbPages
, $nbstr, $this->pages
[$n]);
2567 if($this->DefOrientation
=='P') {
2575 $filter=($this->compress
) ?
'/Filter /FlateDecode ' : '';
2576 for($n=1;$n<=$nb;$n++
) {
2579 $this->_out('<</Type /Page');
2580 $this->_out('/Parent 1 0 R');
2581 if(isset($this->OrientationChanges
[$n])) {
2582 $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt));
2584 $this->_out('/Resources 2 0 R');
2585 if(isset($this->PageLinks
[$n])) {
2587 $annots='/Annots [';
2588 foreach($this->PageLinks
[$n] as $pl) {
2589 $rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+
$pl[2],$pl[1]-$pl[3]);
2590 $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
2591 if(is_string($pl[4])) {
2592 $annots.='/A <</S /URI /URI ('.$this->_escape($pl[4]).')>>>>';
2595 $l=$this->links
[$pl[4]];
2596 $h=isset($this->OrientationChanges
[$l[0]]) ?
$wPt : $hPt;
2597 $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+
2*$l[0],$h-$l[1]*$this->k
);
2600 $this->_out($annots.']');
2602 $this->_out('/Contents '.($this->n+
1).' 0 R>>');
2603 $this->_out('endobj');
2605 $p=($this->compress
) ?
gzcompress($this->pages
[$n]) : $this->pages
[$n];
2607 $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
2608 $this->_putstream($p);
2609 $this->_out('endobj');
2612 $this->offsets
[1]=strlen($this->buffer
);
2613 $this->_out('1 0 obj');
2614 $this->_out('<</Type /Pages');
2616 for($i=0;$i<$nb;$i++
) {
2617 $kids.=(3+
2*$i).' 0 R ';
2619 $this->_out($kids.']');
2620 $this->_out('/Count '.$nb);
2621 $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt));
2623 $this->_out('endobj');
2631 function _putfonts() {
2633 foreach($this->diffs
as $diff) {
2636 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
2637 $this->_out('endobj');
2639 $mqr=get_magic_quotes_runtime();
2640 set_magic_quotes_runtime(0);
2641 foreach($this->FontFiles
as $file=>$info) {
2642 //Font file embedding
2644 $this->FontFiles
[$file]['n']=$this->n
;
2646 $f = fopen($this->_getfontpath().$file,'rb',1);
2648 $this->Error('Font file not found');
2651 $font .= fread($f, 8192);
2654 $compressed=(substr($file,-2)=='.z');
2655 if(!$compressed && isset($info['length2'])) {
2656 $header=(ord($font{0})==128);
2658 //Strip first binary header
2659 $font=substr($font,6);
2661 if($header && ord($font{$info['length1']})==128) {
2662 //Strip second binary header
2663 $font=substr($font,0,$info['length1']).substr($font,$info['length1']+
6);
2666 $this->_out('<</Length '.strlen($font));
2668 $this->_out('/Filter /FlateDecode');
2670 $this->_out('/Length1 '.$info['length1']);
2671 if(isset($info['length2'])) {
2672 $this->_out('/Length2 '.$info['length2'].' /Length3 0');
2675 $this->_putstream($font);
2676 $this->_out('endobj');
2678 set_magic_quotes_runtime($mqr);
2679 foreach($this->fonts
as $k=>$font) {
2681 $this->fonts
[$k]['n']=$this->n+
1;
2682 $type=$font['type'];
2683 $name=$font['name'];
2687 $this->_out('<</Type /Font');
2688 $this->_out('/BaseFont /'.$name);
2689 $this->_out('/Subtype /Type1');
2690 if($name!='Symbol' && $name!='ZapfDingbats') {
2691 $this->_out('/Encoding /WinAnsiEncoding');
2694 $this->_out('endobj');
2695 } elseif($type=='Type1' ||
$type=='TrueType') {
2696 //Additional Type1 or TrueType font
2698 $this->_out('<</Type /Font');
2699 $this->_out('/BaseFont /'.$name);
2700 $this->_out('/Subtype /'.$type);
2701 $this->_out('/FirstChar 32 /LastChar 255');
2702 $this->_out('/Widths '.($this->n+
1).' 0 R');
2703 $this->_out('/FontDescriptor '.($this->n+
2).' 0 R');
2705 if(isset($font['diff'])) {
2706 $this->_out('/Encoding '.($nf+
$font['diff']).' 0 R');
2708 $this->_out('/Encoding /WinAnsiEncoding');
2712 $this->_out('endobj');
2717 for($i=32;$i<=255;$i++
) {
2718 $s.=$cw[chr($i)].' ';
2720 $this->_out($s.']');
2721 $this->_out('endobj');
2724 $s='<</Type /FontDescriptor /FontName /'.$name;
2725 foreach($font['desc'] as $k=>$v) {
2728 $file = $font['file'];
2730 $s.=' /FontFile'.($type=='Type1' ?
'' : '2').' '.$this->FontFiles
[$file]['n'].' 0 R';
2732 $this->_out($s.'>>');
2733 $this->_out('endobj');
2735 //Allow for additional types
2736 $mtd='_put'.strtolower($type);
2737 if(!method_exists($this, $mtd)) {
2738 $this->Error('Unsupported font type: '.$type);
2749 function _putimages() {
2750 $filter=($this->compress
) ?
'/Filter /FlateDecode ' : '';
2751 reset($this->images
);
2752 while(list($file,$info)=each($this->images
)) {
2754 $this->images
[$file]['n']=$this->n
;
2755 $this->_out('<</Type /XObject');
2756 $this->_out('/Subtype /Image');
2757 $this->_out('/Width '.$info['w']);
2758 $this->_out('/Height '.$info['h']);
2759 if($info['cs']=='Indexed') {
2760 $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+
1).' 0 R]');
2763 $this->_out('/ColorSpace /'.$info['cs']);
2764 if($info['cs']=='DeviceCMYK') {
2765 $this->_out('/Decode [1 0 1 0 1 0 1 0]');
2768 $this->_out('/BitsPerComponent '.$info['bpc']);
2769 if(isset($info['f'])) {
2770 $this->_out('/Filter /'.$info['f']);
2772 if(isset($info['parms'])) {
2773 $this->_out($info['parms']);
2775 if(isset($info['trns']) and is_array($info['trns'])) {
2777 for($i=0;$i<count($info['trns']);$i++
) {
2778 $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
2780 $this->_out('/Mask ['.$trns.']');
2782 $this->_out('/Length '.strlen($info['data']).'>>');
2783 $this->_putstream($info['data']);
2784 unset($this->images
[$file]['data']);
2785 $this->_out('endobj');
2787 if($info['cs']=='Indexed') {
2789 $pal=($this->compress
) ?
gzcompress($info['pal']) : $info['pal'];
2790 $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
2791 $this->_putstream($pal);
2792 $this->_out('endobj');
2801 function _putxobjectdict() {
2802 foreach($this->images
as $image) {
2803 $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
2811 function _putresourcedict(){
2812 $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
2813 $this->_out('/Font <<');
2814 foreach($this->fonts
as $font) {
2815 $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
2818 $this->_out('/XObject <<');
2819 $this->_putxobjectdict();
2827 function _putresources() {
2829 $this->_putimages();
2830 //Resource dictionary
2831 $this->offsets
[2]=strlen($this->buffer
);
2832 $this->_out('2 0 obj');
2834 $this->_putresourcedict();
2836 $this->_out('endobj');
2843 function _putinfo() {
2844 $this->_out('/Producer '.$this->_textstring(PDF_PRODUCER
));
2845 if(!empty($this->title
)) {
2846 $this->_out('/Title '.$this->_textstring($this->title
));
2848 if(!empty($this->subject
)) {
2849 $this->_out('/Subject '.$this->_textstring($this->subject
));
2851 if(!empty($this->author
)) {
2852 $this->_out('/Author '.$this->_textstring($this->author
));
2854 if(!empty($this->keywords
)) {
2855 $this->_out('/Keywords '.$this->_textstring($this->keywords
));
2857 if(!empty($this->creator
)) {
2858 $this->_out('/Creator '.$this->_textstring($this->creator
));
2860 $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis')));
2867 function _putcatalog() {
2868 $this->_out('/Type /Catalog');
2869 $this->_out('/Pages 1 0 R');
2870 if($this->ZoomMode
=='fullpage') {
2871 $this->_out('/OpenAction [3 0 R /Fit]');
2873 elseif($this->ZoomMode
=='fullwidth') {
2874 $this->_out('/OpenAction [3 0 R /FitH null]');
2876 elseif($this->ZoomMode
=='real') {
2877 $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
2879 elseif(!is_string($this->ZoomMode
)) {
2880 $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode
/100).']');
2882 if($this->LayoutMode
=='single') {
2883 $this->_out('/PageLayout /SinglePage');
2885 elseif($this->LayoutMode
=='continuous') {
2886 $this->_out('/PageLayout /OneColumn');
2888 elseif($this->LayoutMode
=='two') {
2889 $this->_out('/PageLayout /TwoColumnLeft');
2897 function _puttrailer() {
2898 $this->_out('/Size '.($this->n+
1));
2899 $this->_out('/Root '.$this->n
.' 0 R');
2900 $this->_out('/Info '.($this->n
-1).' 0 R');
2907 function _putheader() {
2908 $this->_out('%PDF-'.$this->PDFVersion
);
2915 function _enddoc() {
2916 $this->_putheader();
2918 $this->_putresources();
2924 $this->_out('endobj');
2928 $this->_putcatalog();
2930 $this->_out('endobj');
2932 $o=strlen($this->buffer
);
2933 $this->_out('xref');
2934 $this->_out('0 '.($this->n+
1));
2935 $this->_out('0000000000 65535 f ');
2936 for($i=1;$i<=$this->n
;$i++
) {
2937 $this->_out(sprintf('%010d 00000 n ',$this->offsets
[$i]));
2940 $this->_out('trailer');
2942 $this->_puttrailer();
2944 $this->_out('startxref');
2946 $this->_out('%%EOF');
2954 function _beginpage($orientation) {
2956 $this->pages
[$this->page
]='';
2958 $this->x
=$this->lMargin
;
2959 $this->y
=$this->tMargin
;
2960 $this->FontFamily
='';
2962 if(empty($orientation)) {
2963 $orientation=$this->DefOrientation
;
2966 $orientation=strtoupper($orientation{0});
2967 if($orientation!=$this->DefOrientation
) {
2968 $this->OrientationChanges
[$this->page
]=true;
2971 if($orientation!=$this->CurOrientation
) {
2972 //Change orientation
2973 if($orientation=='P') {
2974 $this->wPt
=$this->fwPt
;
2975 $this->hPt
=$this->fhPt
;
2980 $this->wPt
=$this->fhPt
;
2981 $this->hPt
=$this->fwPt
;
2985 $this->PageBreakTrigger
=$this->h
-$this->bMargin
;
2986 $this->CurOrientation
=$orientation;
2991 * End of page contents
2994 function _endpage() {
2999 * Begin a new object
3002 function _newobj() {
3004 $this->offsets
[$this->n
]=strlen($this->buffer
);
3005 $this->_out($this->n
.' 0 obj');
3012 function _dounderline($x,$y,$txt) {
3013 $up = $this->CurrentFont
['up'];
3014 $ut = $this->CurrentFont
['ut'];
3015 $w = $this->GetStringWidth($txt) +
$this->ws
* substr_count($txt,' ');
3016 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
);
3020 * Extract info from a JPEG file
3023 function _parsejpg($file) {
3024 $a=GetImageSize($file);
3026 $this->Error('Missing or incorrect image file: '.$file);
3029 $this->Error('Not a JPEG file: '.$file);
3031 if(!isset($a['channels']) or $a['channels']==3) {
3032 $colspace='DeviceRGB';
3034 elseif($a['channels']==4) {
3035 $colspace='DeviceCMYK';
3038 $colspace='DeviceGray';
3040 $bpc=isset($a['bits']) ?
$a['bits'] : 8;
3042 $f=fopen($file,'rb');
3045 $data.=fread($f,4096);
3048 return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
3052 * Extract info from a PNG file
3055 function _parsepng($file) {
3056 $f=fopen($file,'rb');
3058 $this->Error('Can\'t open image file: '.$file);
3061 if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
3062 $this->Error('Not a PNG file: '.$file);
3066 if(fread($f,4)!='IHDR') {
3067 $this->Error('Incorrect PNG file: '.$file);
3069 $w=$this->_freadint($f);
3070 $h=$this->_freadint($f);
3071 $bpc=ord(fread($f,1));
3073 $this->Error('16-bit depth not supported: '.$file);
3075 $ct=ord(fread($f,1));
3077 $colspace='DeviceGray';
3080 $colspace='DeviceRGB';
3083 $colspace='Indexed';
3086 $this->Error('Alpha channel not supported: '.$file);
3088 if(ord(fread($f,1))!=0) {
3089 $this->Error('Unknown compression method: '.$file);
3091 if(ord(fread($f,1))!=0) {
3092 $this->Error('Unknown filter method: '.$file);
3094 if(ord(fread($f,1))!=0) {
3095 $this->Error('Interlacing not supported: '.$file);
3098 $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ?
3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
3099 //Scan chunks looking for palette, transparency and image data
3104 $n=$this->_freadint($f);
3111 elseif($type=='tRNS') {
3112 //Read transparency info
3115 $trns=array(ord(substr($t,1,1)));
3118 $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
3121 $pos=strpos($t,chr(0));
3128 elseif($type=='IDAT') {
3129 //Read image data block
3130 $data.=fread($f,$n);
3133 elseif($type=='IEND') {
3141 if($colspace=='Indexed' and empty($pal)) {
3142 $this->Error('Missing palette in '.$file);
3145 return array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'parms'=>$parms, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data);
3149 * Read a 4-byte integer from file
3152 function _freadint($f) {
3153 //Read a 4-byte integer from file
3154 $a=unpack('Ni',fread($f,4));
3159 * Format a text string
3162 function _textstring($s) {
3163 if($this->isunicode
) {
3164 //Convert string to UTF-16BE
3165 $s = $this->UTF8ToUTF16BE($s, true);
3167 return '('. $this->_escape($s).')';
3171 * Format a text string
3174 function _escapetext($s) {
3175 if($this->isunicode
) {
3176 //Convert string to UTF-16BE
3177 $s = $this->UTF8ToUTF16BE($s, false);
3179 return $this->_escape($s);
3183 * Add \ before \, ( and )
3186 function _escape($s) {
3187 return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\'));
3194 function _putstream($s) {
3195 $this->_out('stream');
3197 $this->_out('endstream');
3201 * Add a line to the document
3205 if($this->state
==2) {
3206 $this->pages
[$this->page
] .= $s."\n";
3209 $this->buffer
.= $s."\n";
3214 * Adds unicode fonts.<br>
3215 * Based on PDF Reference 1.3 (section 5)
3217 * @author Nicola Asuni
3218 * @since 1.52.0.TC005 (2005-01-05)
3220 function _puttruetypeunicode($font) {
3222 // A composite font—a font composed of other fonts, organized hierarchically
3224 $this->_out('<</Type /Font');
3225 $this->_out('/Subtype /Type0');
3226 $this->_out('/BaseFont /'.$font['name'].'');
3227 $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.
3228 $this->_out('/DescendantFonts ['.($this->n +
1).' 0 R]');
3230 $this->_out('endobj');
3233 // A CIDFont whose glyph descriptions are based on TrueType font technology
3235 $this->_out('<</Type /Font');
3236 $this->_out('/Subtype /CIDFontType2');
3237 $this->_out('/BaseFont /'.$font['name'].'');
3238 $this->_out('/CIDSystemInfo '.($this->n +
1).' 0 R');
3239 $this->_out('/FontDescriptor '.($this->n +
2).' 0 R');
3240 if (isset($font['desc']['MissingWidth'])){
3241 $this->_out('/DW '.$font['desc']['MissingWidth'].''); // The default width for glyphs in the CIDFont MissingWidth
3244 foreach ($font['cw'] as $cid => $width) {
3245 $w .= ''.$cid.' ['.$width.'] '; // define a specific width for each individual CID
3247 $this->_out('/W ['.$w.']'); // A description of the widths for the glyphs in the CIDFont
3248 $this->_out('/CIDToGIDMap '.($this->n +
3).' 0 R');
3250 $this->_out('endobj');
3252 // CIDSystemInfo dictionary
3253 // A dictionary containing entries that define the character collection of the CIDFont.
3255 $this->_out('<</Registry (Adobe)'); // A string identifying an issuer of character collections
3256 $this->_out('/Ordering (UCS)'); // A string that uniquely names a character collection issued by a specific registry
3257 $this->_out('/Supplement 0'); // The supplement number of the character collection.
3259 $this->_out('endobj');
3262 // A font descriptor describing the CIDFont’s default metrics other than its glyph widths
3264 $this->_out('<</Type /FontDescriptor');
3265 $this->_out('/FontName /'.$font['name']);
3266 foreach ($font['desc'] as $key => $value) {
3267 $this->_out('/'.$key.' '.$value);
3269 if ($font['file']) {
3270 // A stream containing a TrueType font program
3271 $this->_out('/FontFile2 '.$this->FontFiles
[$font['file']]['n'].' 0 R');
3274 $this->_out('endobj');
3276 // Embed CIDToGIDMap
3277 // A specification of the mapping from CIDs to glyph indices
3279 $ctgfile = $this->_getfontpath().$font['ctg'];
3280 if(!file_exists($ctgfile)) {
3281 $this->Error('Font file not found: '.$ctgfile);
3283 $size = filesize($ctgfile);
3284 $this->_out('<</Length '.$size.'');
3285 if(substr($ctgfile, -2) == '.z') { // check file extension
3286 /* Decompresses data encoded using the public-domain
3287 zlib/deflate compression method, reproducing the
3288 original text or binary data */
3289 $this->_out('/Filter /FlateDecode');
3292 $this->_putstream(file_get_contents($ctgfile));
3293 $this->_out('endobj');
3297 * Converts UTF-8 strings to codepoints array.<br>
3298 * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
3299 * Based on: http://www.faqs.org/rfcs/rfc3629.html
3301 * Char. number range | UTF-8 octet sequence
3302 * (hexadecimal) | (binary)
3303 * --------------------+-----------------------------------------------
3304 * 0000 0000-0000 007F | 0xxxxxxx
3305 * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
3306 * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
3307 * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
3308 * ---------------------------------------------------------------------
3311 * ---------------------------------------------------------------------
3312 * UTF8-octets = *( UTF8-char )
3313 * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
3315 * UTF8-2 = %xC2-DF UTF8-tail
3317 * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
3318 * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
3319 * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
3320 * %xF4 %x80-8F 2( UTF8-tail )
3321 * UTF8-tail = %x80-BF
3322 * ---------------------------------------------------------------------
3324 * @param string $str string to process.
3325 * @return array containing codepoints (UTF-8 characters values)
3327 * @author Nicola Asuni
3328 * @since 1.53.0.TC005 (2005-01-05)
3330 function UTF8StringToArray($str) {
3331 if(!$this->isunicode
) {
3332 return $str; // string is not in unicode
3334 $unicode = array(); // array containing unicode values
3335 $bytes = array(); // array containing single character byte sequences
3336 $numbytes = 1; // number of octetc needed to represent the UTF-8 character
3338 $str .= ""; // force $str to be a string
3339 $length = strlen($str);
3341 for($i = 0; $i < $length; $i++
) {
3342 $char = ord($str{$i}); // get one string character at time
3343 if(count($bytes) == 0) { // get starting octect
3344 if ($char <= 0x7F) {
3345 $unicode[] = $char; // use the character "as is" because is ASCII
3347 } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
3348 $bytes[] = ($char - 0xC0) << 0x06;
3350 } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
3351 $bytes[] = ($char - 0xE0) << 0x0C;
3353 } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
3354 $bytes[] = ($char - 0xF0) << 0x12;
3357 // use replacement character for other invalid sequences
3358 $unicode[] = 0xFFFD;
3362 } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
3363 $bytes[] = $char - 0x80;
3364 if (count($bytes) == $numbytes) {
3365 // compose UTF-8 bytes to a single unicode value
3367 for($j = 1; $j < $numbytes; $j++
) {
3368 $char +
= ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
3370 if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
3371 /* The definition of UTF-8 prohibits encoding character numbers between
3372 U+D800 and U+DFFF, which are reserved for use with the UTF-16
3373 encoding form (as surrogate pairs) and do not directly represent
3375 $unicode[] = 0xFFFD; // use replacement character
3378 $unicode[] = $char; // add char to array
3380 // reset data for next char
3385 // use replacement character for other invalid sequences
3386 $unicode[] = 0xFFFD;
3395 * Converts UTF-8 strings to UTF16-BE.<br>
3396 * Based on: http://www.faqs.org/rfcs/rfc2781.html
3400 * Encoding of a single character from an ISO 10646 character value to
3401 * UTF-16 proceeds as follows. Let U be the character number, no greater
3404 * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
3407 * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
3408 * U' must be less than or equal to 0xFFFFF. That is, U' can be
3409 * represented in 20 bits.
3411 * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
3412 * 0xDC00, respectively. These integers each have 10 bits free to
3413 * encode the character value, for a total of 20 bits.
3415 * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
3416 * bits of W1 and the 10 low-order bits of U' to the 10 low-order
3417 * bits of W2. Terminate.
3419 * Graphically, steps 2 through 4 look like:
3420 * U' = yyyyyyyyyyxxxxxxxxxx
3421 * W1 = 110110yyyyyyyyyy
3422 * W2 = 110111xxxxxxxxxx
3424 * @param string $str string to process.
3425 * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
3428 * @author Nicola Asuni
3429 * @since 1.53.0.TC005 (2005-01-05)
3430 * @uses UTF8StringToArray
3432 function UTF8ToUTF16BE($str, $setbom=true) {
3433 if(!$this->isunicode
) {
3434 return $str; // string is not in unicode
3436 $outstr = ""; // string to be returned
3437 $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
3438 $numitems = count($unicode);
3441 $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
3443 foreach($unicode as $char) {
3444 if($char == 0xFFFD) {
3445 $outstr .= "\xFF\xFD"; // replacement character
3446 } elseif ($char < 0x10000) {
3447 $outstr .= chr($char >> 0x08);
3448 $outstr .= chr($char & 0xFF);
3451 $w1 = 0xD800 |
($char >> 0x10);
3452 $w2 = 0xDC00 |
($char & 0x3FF);
3453 $outstr .= chr($w1 >> 0x08);
3454 $outstr .= chr($w1 & 0xFF);
3455 $outstr .= chr($w2 >> 0x08);
3456 $outstr .= chr($w2 & 0xFF);
3462 // ====================================================
3466 * @param array $font font
3469 function setHeaderFont($font) {
3470 $this->header_font
= $font;
3475 * @param array $font font
3478 function setFooterFont($font) {
3479 $this->footer_font
= $font;
3483 * Set language array.
3484 * @param array $language
3487 function setLanguageArray($language) {
3488 $this->l
= $language;
3492 * Set document barcode.
3493 * @param string $bc barcode
3495 function setBarcode($bc="") {
3496 $this->barcode
= $bc;
3501 * @param int $x x position in user units
3502 * @param int $y y position in user units
3503 * @param int $w width in user units
3504 * @param int $h height position in user units
3505 * @param string $type type of barcode (I25, C128A, C128B, C128C, C39)
3506 * @param string $style barcode style
3507 * @param string $font font for text
3508 * @param int $xres x resolution
3509 * @param string $code code to print
3511 function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) {
3512 require_once(dirname(__FILE__
)."/barcode/barcode.php");
3513 require_once(dirname(__FILE__
)."/barcode/i25object.php");
3514 require_once(dirname(__FILE__
)."/barcode/c39object.php");
3515 require_once(dirname(__FILE__
)."/barcode/c128aobject.php");
3516 require_once(dirname(__FILE__
)."/barcode/c128bobject.php");
3517 require_once(dirname(__FILE__
)."/barcode/c128cobject.php");
3523 if (empty($style)) {
3524 $style = BCS_ALIGN_LEFT
;
3525 $style |
= BCS_IMAGE_PNG
;
3526 $style |
= BCS_TRANSPARENT
;
3527 //$style |= BCS_BORDER;
3528 //$style |= BCS_DRAW_TEXT;
3529 //$style |= BCS_STRETCH_TEXT;
3530 //$style |= BCS_REVERSE_COLOR;
3532 if (empty($font)) {$font = BCD_DEFAULT_FONT
;}
3533 if (empty($xres)) {$xres = BCD_DEFAULT_XRES
;}
3535 $scale_factor = 1.5 * $xres * $this->k
;
3536 $bc_w = round($w * $scale_factor); //width in points
3537 $bc_h = round($h * $scale_factor); //height in points
3539 switch (strtoupper($type)) {
3541 $obj = new I25Object($bc_w, $bc_h, $style, $code);
3545 $obj = new C128AObject($bc_w, $bc_h, $style, $code);
3550 $obj = new C128BObject($bc_w, $bc_h, $style, $code);
3554 $obj = new C128CObject($bc_w, $bc_h, $style, $code);
3558 $obj = new C39Object($bc_w, $bc_h, $style, $code);
3563 $obj->SetFont($font);
3564 $obj->DrawObject($xres);
3566 //use a temporary file....
3567 $tmpName = tempnam(K_PATH_CACHE
,'img');
3568 imagepng($obj->getImage(), $tmpName);
3569 $this->Image($tmpName, $x, $y, $w, $h, 'png');
3570 $obj->DestroyObject();
3576 * Returns the PDF data.
3578 function getPDFData() {
3579 if($this->state
< 3) {
3582 return $this->buffer
;
3585 // --- HTML PARSER FUNCTIONS ---
3588 * Allows to preserve some HTML formatting.<br />
3589 * 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
3590 * @param string $html text to display
3591 * @param boolean $ln if true add a new line after text (default = true)
3592 * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
3594 function writeHTML($html, $ln=true, $fill=0) {
3596 // store some variables
3597 $html=strip_tags($html,"<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>"); //remove all unsupported tags
3598 //replace carriage returns, newlines and tabs
3599 $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
3600 $html = strtr($html, $repTable);
3601 $pattern = '/(<[^>]+>)/Uu';
3602 $a = preg_split($pattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
); //explodes the string
3604 if (empty($this->lasth
)) {
3606 $this->lasth
= $this->FontSize
* K_CELL_HEIGHT_RATIO
;
3609 foreach($a as $key=>$element) {
3610 if (!preg_match($pattern, $element)) {
3613 $this->addHtmlLink($this->HREF
, $element, $fill);
3615 elseif($this->tdbegin
) {
3616 if((strlen(trim($element)) > 0) AND ($element != " ")) {
3617 $this->Cell($this->tdwidth
, $this->tdheight
, $this->unhtmlentities($element), $this->tableborder
, '', $this->tdalign
, $this->tdbgcolor
);
3619 elseif($element == " ") {
3620 $this->Cell($this->tdwidth
, $this->tdheight
, '', $this->tableborder
, '', $this->tdalign
, $this->tdbgcolor
);
3624 $this->Write($this->lasth
, stripslashes($this->unhtmlentities($element)), '', $fill);
3628 $element = substr($element, 1, -1);
3630 if($element{0}=='/') {
3631 $this->closedHTMLTagHandler(strtolower(substr($element, 1)));
3634 //Extract attributes
3636 preg_match('/([a-zA-Z0-9]*)/', $element, $tag);
3637 $tag = strtolower($tag[0]);
3639 preg_match_all('/([^=\s]*)=["\']?([^"\']*)["\']?/', $element, $attr_array, PREG_PATTERN_ORDER
);
3640 $attr = array(); // reset attribute array
3641 while(list($id,$name)=each($attr_array[1])) {
3642 $attr[strtolower($name)] = $attr_array[2][$id];
3644 $this->openHTMLTagHandler($tag, $attr, $fill);
3649 $this->Ln($this->lasth
);
3654 * 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 />
3655 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
3656 * @param float $w Cell width. If 0, the cell extends up to the right margin.
3657 * @param float $h Cell minimum height. The cell extends automatically if needed.
3658 * @param float $x upper-left corner X coordinate
3659 * @param float $y upper-left corner Y coordinate
3660 * @param string $html html text to print. Default value: empty string.
3661 * @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>
3662 * @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>
3663 Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
3664 * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
3667 function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0) {
3669 if (empty($this->lasth
)) {
3671 $this->lasth
= $this->FontSize
* K_CELL_HEIGHT_RATIO
;
3681 // get current page number
3682 $pagenum = $this->page
;
3688 $w = $this->fw
- $x - $this->rMargin
;
3691 // store original margin values
3692 $lMargin = $this->lMargin
;
3693 $rMargin = $this->rMargin
;
3695 // set new margin values
3696 $this->SetLeftMargin($x);
3697 $this->SetRightMargin($this->fw
- $x - $w);
3699 // calculate remaining vertical space on page
3700 $restspace = $this->getPageHeight() - $this->GetY() - $this->getBreakMargin();
3702 $this->writeHTML($html, true, $fill); // write html text
3704 $currentY = $this->GetY();
3706 // check if a new page has been created
3707 if ($this->page
> $pagenum) {
3708 // design a cell around the text on first page
3709 $currentpage = $this->page
;
3710 $this->page
= $pagenum;
3711 $this->SetY($this->getPageHeight() - $restspace - $this->getBreakMargin());
3712 $h = $restspace - 1;
3713 $this->Cell($w, $h, "", $border, $ln, 'L', 0);
3714 // design a cell around the text on last page
3715 $this->page
= $currentpage;
3716 $h = $currentY - $this->tMargin
;
3717 $this->SetY($this->tMargin
); // put cursor at the beginning of text
3718 $this->Cell($w, $h, "", $border, $ln, 'L', 0);
3720 $h = max($h, ($currentY - $y));
3721 $this->SetY($y); // put cursor at the beginning of text
3722 // design a cell around the text
3723 $this->Cell($w, $h, "", $border, $ln, 'L', 0);
3726 // restore original margin values
3727 $this->SetLeftMargin($lMargin);
3728 $this->SetRightMargin($rMargin);
3736 * Process opening tags.
3737 * @param string $tag tag name (in uppercase)
3738 * @param string $attr tag attribute (in uppercase)
3739 * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
3742 function openHTMLTagHandler($tag, $attr, $fill=0) {
3746 if ((isset($attr['border'])) AND ($attr['border'] != '')) {
3747 $this->tableborder
= $attr['border'];
3750 $this->tableborder
= 0;
3759 if ((isset($attr['width'])) AND ($attr['width'] != '')) {
3760 $this->tdwidth
= ($attr['width']/4);
3763 $this->tdwidth
= (($this->w
- $this->lMargin
- $this->rMargin
) / $this->default_table_columns
);
3765 if ((isset($attr['height'])) AND ($attr['height'] != '')) {
3766 $this->tdheight
=($attr['height'] / $this->k
);
3769 $this->tdheight
= $this->lasth
;
3771 if ((isset($attr['align'])) AND ($attr['align'] != '')) {
3772 switch ($attr['align']) {
3774 $this->tdalign
= "C";
3778 $this->tdalign
= "R";
3783 $this->tdalign
= "L";
3788 if ((isset($attr['bgcolor'])) AND ($attr['bgcolor'] != '')) {
3789 $coul = $this->convertColorHexToDec($attr['bgcolor']);
3790 $this->SetFillColor($coul['R'], $coul['G'], $coul['B']);
3791 $this->tdbgcolor
=true;
3793 $this->tdbegin
=true;
3798 if ((isset($attr['width'])) AND ($attr['width'] != '')) {
3799 $hrWidth = $attr['width'];
3802 $hrWidth = $this->w
- $this->lMargin
- $this->rMargin
;
3806 $this->SetLineWidth(0.2);
3807 $this->Line($x, $y, $x +
$hrWidth, $y);
3808 $this->SetLineWidth(0.2);
3813 $this->setStyle('b', true);
3817 $this->setStyle('i', true);
3823 $this->setStyle($tag, true);
3827 $this->HREF
= $attr['href'];
3831 if(isset($attr['src'])) {
3832 // replace relative path with real server path
3833 $attr['src'] = str_replace(K_PATH_URL_CACHE
, K_PATH_CACHE
, $attr['src']);
3834 if(!isset($attr['width'])) {
3837 if(!isset($attr['height'])) {
3838 $attr['height'] = 0;
3841 $this->Image($attr['src'], $this->GetX(),$this->GetY(), $this->pixelsToMillimeters($attr['width']), $this->pixelsToMillimeters($attr['height']));
3842 //$this->SetX($this->img_rb_x);
3843 $this->SetY($this->img_rb_y
);
3849 $this->listordered
= false;
3850 $this->listcount
= 0;
3854 $this->listordered
= true;
3855 $this->listcount
= 0;
3860 if ($this->listordered
) {
3861 $this->lispacer
= " ".(++
$this->listcount
).". ";
3864 //unordered list simbol
3865 $this->lispacer
= " - ";
3867 $this->Write($this->lasth
, $this->lispacer
, '', $fill);
3874 if(strlen($this->lispacer
) > 0) {
3875 $this->x +
= $this->GetStringWidth($this->lispacer
);
3885 $currentFontSize = $this->FontSize
;
3886 $this->tempfontsize
= $this->FontSizePt
;
3887 $this->SetFontSize($this->FontSizePt
* K_SMALL_RATIO
);
3888 $this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize
)*(K_SMALL_RATIO
)));
3892 $currentFontSize = $this->FontSize
;
3893 $this->tempfontsize
= $this->FontSizePt
;
3894 $this->SetFontSize($this->FontSizePt
* K_SMALL_RATIO
);
3895 $this->SetXY($this->GetX(), $this->GetY() +
(($currentFontSize - $this->FontSize
)*(K_SMALL_RATIO
)));
3899 $currentFontSize = $this->FontSize
;
3900 $this->tempfontsize
= $this->FontSizePt
;
3901 $this->SetFontSize($this->FontSizePt
* K_SMALL_RATIO
);
3902 $this->SetXY($this->GetX(), $this->GetY() +
(($currentFontSize - $this->FontSize
)/3));
3906 if (isset($attr['color']) AND $attr['color']!='') {
3907 $coul = $this->convertColorHexToDec($attr['color']);
3908 $this->SetTextColor($coul['R'],$coul['G'],$coul['B']);
3909 $this->issetcolor
=true;
3911 if (isset($attr['face']) and in_array(strtolower($attr['face']), $this->fontlist
)) {
3912 $this->SetFont(strtolower($attr['FACE']));
3913 $this->issetfont
=true;
3915 if (isset($attr['size'])) {
3916 $headsize = intval($attr['size']);
3920 $currentFontSize = $this->FontSize
;
3921 $this->tempfontsize
= $this->FontSizePt
;
3922 $this->SetFontSize($this->FontSizePt +
$headsize);
3923 $this->lasth
= $this->FontSize
* K_CELL_HEIGHT_RATIO
;
3932 $headsize = (4 - substr($tag, 1)) * 2;
3933 $currentFontSize = $this->FontSize
;
3934 $this->tempfontsize
= $this->FontSizePt
;
3935 $this->SetFontSize($this->FontSizePt +
$headsize);
3936 $this->setStyle('b', true);
3937 $this->lasth
= $this->FontSize
* K_CELL_HEIGHT_RATIO
;
3944 * Process closing tags.
3945 * @param string $tag tag name (in uppercase)
3948 function closedHTMLTagHandler($tag) {
3953 $this->tdbegin
= false;
3955 $this->tdheight
= 0;
3956 $this->tdalign
= "L";
3957 $this->tdbgcolor
= false;
3958 $this->SetFillColor($this->prevFillColor
[0], $this->prevFillColor
[1], $this->prevFillColor
[2]);
3966 $this->tableborder
=0;
3970 $this->setStyle('b', false);
3973 $this->setStyle('i', false);
3978 $this->setStyle($tag, false);
3986 $currentFontSize = $this->FontSize
;
3987 $this->SetFontSize($this->tempfontsize
);
3988 $this->tempfontsize
= $this->FontSizePt
;
3989 $this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize
)*(K_SMALL_RATIO
)));
3993 $currentFontSize = $this->FontSize
;
3994 $this->SetFontSize($this->tempfontsize
);
3995 $this->tempfontsize
= $this->FontSizePt
;
3996 $this->SetXY($this->GetX(), $this->GetY() +
(($currentFontSize - $this->FontSize
)*(K_SMALL_RATIO
)));
4000 $currentFontSize = $this->FontSize
;
4001 $this->SetFontSize($this->tempfontsize
);
4002 $this->tempfontsize
= $this->FontSizePt
;
4003 $this->SetXY($this->GetX(), $this->GetY() - (($this->FontSize
- $currentFontSize)/3));
4007 if ($this->issetcolor
== true) {
4008 $this->SetTextColor($this->prevTextColor
[0], $this->prevTextColor
[1], $this->prevTextColor
[2]);
4010 if ($this->issetfont
) {
4011 $this->FontFamily
= $this->prevFontFamily
;
4012 $this->FontStyle
= $this->prevFontStyle
;
4013 $this->SetFont($this->FontFamily
);
4014 $this->issetfont
= false;
4016 $currentFontSize = $this->FontSize
;
4017 $this->SetFontSize($this->tempfontsize
);
4018 $this->tempfontsize
= $this->FontSizePt
;
4019 //$this->TextColor = $this->prevTextColor;
4020 $this->lasth
= $this->FontSize
* K_CELL_HEIGHT_RATIO
;
4032 $this->lispacer
= "";
4041 $currentFontSize = $this->FontSize
;
4042 $this->SetFontSize($this->tempfontsize
);
4043 $this->tempfontsize
= $this->FontSizePt
;
4044 $this->setStyle('b', false);
4046 $this->lasth
= $this->FontSize
* K_CELL_HEIGHT_RATIO
;
4057 * @param string $tag tag name (in lowercase)
4058 * @param boolean $enable
4061 function setStyle($tag, $enable) {
4062 //Modify style and select corresponding font
4063 $this->$tag +
= ($enable ?
1 : -1);
4065 foreach(array('b', 'i', 'u') as $s) {
4070 $this->SetFont('', $style);
4074 * Output anchor link.
4075 * @param string $url link URL
4076 * @param string $name link name
4077 * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
4080 function addHtmlLink($url, $name, $fill=0) {
4082 $this->SetTextColor(0, 0, 255);
4083 $this->setStyle('u', true);
4084 $this->Write($this->lasth
, $name, $url, $fill);
4085 $this->setStyle('u', false);
4086 $this->SetTextColor(0);
4090 * Returns an associative array (keys: R,G,B) from
4091 * a hex html code (e.g. #3FE5AA).
4092 * @param string $color hexadecimal html color [#rrggbb]
4096 function convertColorHexToDec($color = "#000000"){
4097 $tbl_color = array();
4098 $tbl_color['R'] = hexdec(substr($color, 1, 2));
4099 $tbl_color['G'] = hexdec(substr($color, 3, 2));
4100 $tbl_color['B'] = hexdec(substr($color, 5, 2));
4105 * Converts pixels to millimeters in 72 dpi.
4106 * @param int $px pixels
4107 * @return float millimeters
4110 function pixelsToMillimeters($px){
4111 return $px * 25.4 / 72;
4115 * Reverse function for htmlentities.
4116 * Convert entities in UTF-8.
4118 * @param $text_to_convert Text to convert.
4119 * @return string converted
4121 function unhtmlentities($text_to_convert) {
4122 require_once(dirname(__FILE__
).'/html_entity_decode_php4.php');
4123 return html_entity_decode_php4($text_to_convert);
4127 //Handle special IE contype request
4128 if(isset($_SERVER['HTTP_USER_AGENT']) AND ($_SERVER['HTTP_USER_AGENT']=='contype')) {
4129 header('Content-Type: application/pdf');
4134 //============================================================+
4136 //============================================================+