2
//============================================================+
3
// File name : tcpdf.php
5
// Last Update : 2006-10-27
6
// Author : Nicola Asuni
7
// Version : 1.53.0.TC026_PHP4
8
// License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
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
// Disabled in phpMyAdmin
36
//require_once(dirname(__FILE__).'/config/tcpdf_config.php');
41
* @package com.tecnick.tcpdf
45
* This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
46
* TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
47
* <h3>TCPDF main changes from FPDF are:</h3><ul>
48
* <li>PHP4 porting</li>
49
* <li>UTF-8 Unicode support</li>
50
* <li>source code clean up</li>
51
* <li>code style and formatting</li>
52
* <li>source code documentation using phpDocumentor (www.phpdoc.org)</li>
53
* <li>All ISO page formats were included</li>
54
* <li>image scale factor</li>
55
* <li>includes methods to parse and printsome XHTML code, supporting the following elements: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small;</li>
56
* <li>includes a method to print various barcode formats using an improved version of "Generic Barcode Render Class" by Karim Mribti (http://www.mribti.com/barcode/) (require GD library: http://www.boutell.com/gd/)</li>
57
* <li>defines standard Header() and Footer() methods.</li>
59
* Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p>
61
* @package com.tecnick.tcpdf
62
* @abstract Class for generating PDF files on-the-fly without requiring external extensions.
63
* @author Nicola Asuni
64
* @copyright 2004-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY - www.tecnick.com - info@tecnick.com
65
* @link http://tcpdf.sourceforge.net
66
* @license http://www.gnu.org/copyleft/lesser.html LGPL
67
@version 1.53.0.TC026_PHP4
70
if(!class_exists('TCPDF')) {
72
* define default PDF document producer
74
define('PDF_PRODUCER','TCPDF 1.53.0.TC026_PHP4 (http://tcpdf.sourceforge.net)');
77
* This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
78
* This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
79
* This version contains some changes: [porting to PHP4, support for UTF-8 Unicode, code style and formatting, php documentation (www.phpdoc.org), ISO page formats, minor improvements, image scale factor]<br>
80
* TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
81
* To add your own TTF fonts please read /fonts/README.TXT
83
* @package com.tecnick.tcpdf
84
* @version 1.53.0.TC026_PHP4
85
* @author Nicola Asuni
86
* @link http://tcpdf.sourceforge.net
87
* @license http://www.gnu.org/copyleft/lesser.html LGPL
93
* @var current page number
99
* @var current object number
105
* @var array of object offsets
111
* @var buffer holding in-memory PDF
117
* @var array containing pages
123
* @var current document state
129
* @var compression flag
135
* @var default orientation
141
* @var current orientation
147
* @var array indicating orientation changes
150
var $OrientationChanges;
153
* @var scale factor (number of points in user unit)
159
* @var width of page format in points
165
* @var height of page format in points
171
* @var width of page format in user unit
177
* @var height of page format in user unit
183
* @var current width of page in points
189
* @var current height of page in points
195
* @var current width of page in user unit
201
* @var current height of page in user unit
225
* @var page break margin
237
* @var current horizontal position in user unit for cell positioning
243
* @var current vertical position in user unit for cell positioning
249
* @var height of last cell printed
255
* @var line width in user unit
261
* @var array of standard font names
267
* @var array of used fonts
273
* @var array of font files
279
* @var array of encoding differences
285
* @var array of used images
291
* @var array of links in pages
297
* @var array of internal links
303
* @var current font family
309
* @var current font style
315
* @var underlining flag
321
* @var current font info
327
* @var current font size in points
333
* @var current font size in user unit
339
* @var commands for drawing color
345
* @var commands for filling color
351
* @var commands for text color
357
* @var indicates whether fill and text colors are different
369
* @var automatic page breaking
375
* @var threshold used to trigger page breaks
378
var $PageBreakTrigger;
381
* @var flag set when processing footer
387
* @var zoom display mode
393
* @var layout display mode
429
* @var alias for total number of pages
435
* @var right-bottom corner X coordinate of inserted image
437
* @author Nicola Asuni
443
* @var right-bottom corner Y coordinate of inserted image
445
* @author Nicola Asuni
451
* @var image scale factor
453
* @author Nicola Asuni
459
* @var boolean set to true when the input text is unicode (require unicode fonts)
461
* @author Nicola Asuni
464
var $isunicode = false;
471
var $PDFVersion = "1.3";
474
// ----------------------
477
* @var Minimum distance between header and top page margin.
483
* @var Minimum distance between footer and bottom page margin.
489
* @var original left margin value
491
* @since 1.53.0.TC013
493
var $original_lMargin;
496
* @var original right margin value
498
* @since 1.53.0.TC013
500
var $original_rMargin;
515
* @var Language templates.
521
* @var Barcode to print on page footer (only if set).
524
var $barcode = false;
527
* @var If true prints header
530
var $print_header = true;
533
* @var If true prints footer.
536
var $print_footer = true;
539
* @var Header width (0 = full page width).
542
var $header_width = 0;
545
* @var Header image logo.
548
var $header_logo = "";
551
* @var Header image logo width in mm.
554
var $header_logo_width = 30;
557
* @var String to print as title on document header.
560
var $header_title = "";
563
* @var String to print on document header.
566
var $header_string = "";
569
* @var Default number of columns for html table.
572
var $default_table_columns = 4;
575
// variables for html parser
578
* @var HTML PARSER: store current link.
584
* @var HTML PARSER: store font list.
590
* @var HTML PARSER: true when font attribute is set.
596
* @var HTML PARSER: true when color attribute is set.
602
* @var HTML PARSER: true in case of ordered list (OL), false otherwise.
605
var $listordered = false;
608
* @var HTML PARSER: count list items.
614
* @var HTML PARSER: size of table border.
617
var $tableborder = 0;
620
* @var HTML PARSER: true at the beginning of table.
623
var $tdbegin = false;
626
* @var HTML PARSER: table width.
632
* @var HTML PARSER: table height.
638
* @var HTML PARSER: table align.
644
* @var HTML PARSER: table background color.
647
var $tdbgcolor = false;
650
* @var Store temporary font size in points.
653
var $tempfontsize = 10;
656
* @var Bold font style status.
662
* @var Underlined font style status.
668
* @var Italic font style status.
674
* @var spacer for LI tags.
680
* @var default encoding
682
* @since 1.53.0.TC010
684
var $encoding = "UTF-8";
687
* @var PHP internal encoding
689
* @since 1.53.0.TC016
691
var $internal_encoding;
694
* @var store previous fill color as RGB array
696
* @since 1.53.0.TC017
698
var $prevFillColor = array(255,255,255);
701
* @var store previous text color as RGB array
703
* @since 1.53.0.TC017
705
var $prevTextColor = array(0,0,0);
708
* @var store previous font family
710
* @since 1.53.0.TC017
715
* @var store previous font style
717
* @since 1.53.0.TC017
721
//------------------------------------------------------------
723
//------------------------------------------------------------
726
* This is the class constructor.
727
* It allows to set up the page format, the orientation and
728
* the measure unit used in all the methods (except for the font sizes).
730
* @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
731
* @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
732
* @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
733
* @param boolean $unicode TRUE means that the input text is unicode (default = true)
734
* @param String $encoding charset encoding; default is UTF-8
736
function TCPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding="UTF-8") {
738
/* Set internal character encoding to ASCII */
739
if (function_exists("mb_internal_encoding") AND mb_internal_encoding()) {
740
$this->internal_encoding = mb_internal_encoding();
741
mb_internal_encoding("ASCII");
746
//Initialization of properties
747
$this->isunicode=$unicode;
751
$this->pages=array();
752
$this->OrientationChanges=array();
754
$this->fonts=array();
755
$this->FontFiles=array();
756
$this->diffs=array();
757
$this->images=array();
758
$this->links=array();
759
$this->InFooter=false;
761
$this->FontFamily='';
763
$this->FontSizePt=12;
764
$this->underline=false;
765
$this->DrawColor='0 G';
766
$this->FillColor='0 g';
767
$this->TextColor='0 g';
768
$this->ColorFlag=false;
770
//Standard Unicode fonts
771
$this->CoreFonts=array(
772
'courier'=>'Courier',
773
'courierB'=>'Courier-Bold',
774
'courierI'=>'Courier-Oblique',
775
'courierBI'=>'Courier-BoldOblique',
776
'helvetica'=>'Helvetica',
777
'helveticaB'=>'Helvetica-Bold',
778
'helveticaI'=>'Helvetica-Oblique',
779
'helveticaBI'=>'Helvetica-BoldOblique',
780
'times'=>'Times-Roman',
781
'timesB'=>'Times-Bold',
782
'timesI'=>'Times-Italic',
783
'timesBI'=>'Times-BoldItalic',
785
'zapfdingbats'=>'ZapfDingbats'
789
// 2003-06-11 - Nicola Asuni : changed if/else with switch statement
790
switch (strtolower($unit)){
791
case 'pt': {$this->k=1; break;}
792
case 'mm': {$this->k=72/25.4; break;}
793
case 'cm': {$this->k=72/2.54; break;}
794
case 'in': {$this->k=72; break;}
795
default : {$this->Error('Incorrect unit: '.$unit); break;}
799
if(is_string($format)) {
800
// 2002-07-24 - Nicola Asuni (info@tecnick.com)
801
// Added new page formats (45 standard ISO paper formats and 4 american common formats).
802
// Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
803
switch (strtoupper($format)){
804
case '4A0': {$format = array(4767.87,6740.79); break;}
805
case '2A0': {$format = array(3370.39,4767.87); break;}
806
case 'A0': {$format = array(2383.94,3370.39); break;}
807
case 'A1': {$format = array(1683.78,2383.94); break;}
808
case 'A2': {$format = array(1190.55,1683.78); break;}
809
case 'A3': {$format = array(841.89,1190.55); break;}
810
case 'A4': default: {$format = array(595.28,841.89); break;}
811
case 'A5': {$format = array(419.53,595.28); break;}
812
case 'A6': {$format = array(297.64,419.53); break;}
813
case 'A7': {$format = array(209.76,297.64); break;}
814
case 'A8': {$format = array(147.40,209.76); break;}
815
case 'A9': {$format = array(104.88,147.40); break;}
816
case 'A10': {$format = array(73.70,104.88); break;}
817
case 'B0': {$format = array(2834.65,4008.19); break;}
818
case 'B1': {$format = array(2004.09,2834.65); break;}
819
case 'B2': {$format = array(1417.32,2004.09); break;}
820
case 'B3': {$format = array(1000.63,1417.32); break;}
821
case 'B4': {$format = array(708.66,1000.63); break;}
822
case 'B5': {$format = array(498.90,708.66); break;}
823
case 'B6': {$format = array(354.33,498.90); break;}
824
case 'B7': {$format = array(249.45,354.33); break;}
825
case 'B8': {$format = array(175.75,249.45); break;}
826
case 'B9': {$format = array(124.72,175.75); break;}
827
case 'B10': {$format = array(87.87,124.72); break;}
828
case 'C0': {$format = array(2599.37,3676.54); break;}
829
case 'C1': {$format = array(1836.85,2599.37); break;}
830
case 'C2': {$format = array(1298.27,1836.85); break;}
831
case 'C3': {$format = array(918.43,1298.27); break;}
832
case 'C4': {$format = array(649.13,918.43); break;}
833
case 'C5': {$format = array(459.21,649.13); break;}
834
case 'C6': {$format = array(323.15,459.21); break;}
835
case 'C7': {$format = array(229.61,323.15); break;}
836
case 'C8': {$format = array(161.57,229.61); break;}
837
case 'C9': {$format = array(113.39,161.57); break;}
838
case 'C10': {$format = array(79.37,113.39); break;}
839
case 'RA0': {$format = array(2437.80,3458.27); break;}
840
case 'RA1': {$format = array(1729.13,2437.80); break;}
841
case 'RA2': {$format = array(1218.90,1729.13); break;}
842
case 'RA3': {$format = array(864.57,1218.90); break;}
843
case 'RA4': {$format = array(609.45,864.57); break;}
844
case 'SRA0': {$format = array(2551.18,3628.35); break;}
845
case 'SRA1': {$format = array(1814.17,2551.18); break;}
846
case 'SRA2': {$format = array(1275.59,1814.17); break;}
847
case 'SRA3': {$format = array(907.09,1275.59); break;}
848
case 'SRA4': {$format = array(637.80,907.09); break;}
849
case 'LETTER': {$format = array(612.00,792.00); break;}
850
case 'LEGAL': {$format = array(612.00,1008.00); break;}
851
case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
852
case 'FOLIO': {$format = array(612.00,936.00); break;}
853
// default: {$this->Error('Unknown page format: '.$format); break;}
854
// END CHANGES Nicola Asuni
856
$this->fwPt=$format[0];
857
$this->fhPt=$format[1];
860
$this->fwPt=$format[0]*$this->k;
861
$this->fhPt=$format[1]*$this->k;
864
$this->fw=$this->fwPt/$this->k;
865
$this->fh=$this->fhPt/$this->k;
868
$orientation=strtolower($orientation);
869
if($orientation=='p' or $orientation=='portrait') {
870
$this->DefOrientation='P';
871
$this->wPt=$this->fwPt;
872
$this->hPt=$this->fhPt;
874
elseif($orientation=='l' or $orientation=='landscape') {
875
$this->DefOrientation='L';
876
$this->wPt=$this->fhPt;
877
$this->hPt=$this->fwPt;
880
$this->Error('Incorrect orientation: '.$orientation);
883
$this->CurOrientation=$this->DefOrientation;
884
$this->w=$this->wPt/$this->k;
885
$this->h=$this->hPt/$this->k;
886
//Page margins (1 cm)
887
$margin=28.35/$this->k;
888
$this->SetMargins($margin,$margin);
889
//Interior cell margin (1 mm)
890
$this->cMargin=$margin/10;
891
//Line width (0.2 mm)
892
$this->LineWidth=.567/$this->k;
893
//Automatic page break
894
$this->SetAutoPageBreak(true,2*$margin);
895
//Full width display mode
896
$this->SetDisplayMode('fullwidth');
898
$this->SetCompression(true);
899
//Set default PDF version number
900
$this->PDFVersion = "1.3";
902
$this->encoding = $encoding;
907
$this->fontlist = array("arial", "times", "courier", "helvetica", "symbol");
908
$this->issetfont = false;
909
$this->issetcolor = false;
910
$this->tableborder = 0;
911
$this->tdbegin = false;
914
$this->tdalign = "L";
915
$this->tdbgcolor = false;
917
$this->SetFillColor(200, 200, 200, true);
918
$this->SetTextColor(0, 0, 0, true);
922
* Set the image scale.
923
* @param float $scale image scale.
924
* @author Nicola Asuni
927
function setImageScale($scale) {
928
$this->imgscale=$scale;
932
* Returns the image scale.
933
* @return float image scale.
934
* @author Nicola Asuni
937
function getImageScale() {
938
return $this->imgscale;
942
* Returns the page width in units.
943
* @return int page width.
944
* @author Nicola Asuni
947
function getPageWidth() {
952
* Returns the page height in units.
953
* @return int page height.
954
* @author Nicola Asuni
957
function getPageHeight() {
962
* Returns the page break margin.
963
* @return int page break margin.
964
* @author Nicola Asuni
967
function getBreakMargin() {
968
return $this->bMargin;
972
* Returns the scale factor (number of points in user unit).
973
* @return int scale factor.
974
* @author Nicola Asuni
977
function getScaleFactor() {
982
* Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
983
* @param float $left Left margin.
984
* @param float $top Top margin.
985
* @param float $right Right margin. Default value is the left one.
987
* @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
989
function SetMargins($left, $top, $right=-1) {
990
//Set left, top and right margins
991
$this->lMargin=$left;
996
$this->rMargin=$right;
1000
* Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
1001
* @param float $margin The margin.
1003
* @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
1005
function SetLeftMargin($margin) {
1007
$this->lMargin=$margin;
1008
if(($this->page>0) and ($this->x<$margin)) {
1014
* Defines the top margin. The method can be called before creating the first page.
1015
* @param float $margin The margin.
1017
* @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
1019
function SetTopMargin($margin) {
1021
$this->tMargin=$margin;
1025
* Defines the right margin. The method can be called before creating the first page.
1026
* @param float $margin The margin.
1028
* @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
1030
function SetRightMargin($margin) {
1032
$this->rMargin=$margin;
1036
* Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
1037
* @param boolean $auto Boolean indicating if mode should be on or off.
1038
* @param float $margin Distance from the bottom of the page.
1040
* @see Cell(), MultiCell(), AcceptPageBreak()
1042
function SetAutoPageBreak($auto, $margin=0) {
1043
//Set auto page break mode and triggering margin
1044
$this->AutoPageBreak=$auto;
1045
$this->bMargin=$margin;
1046
$this->PageBreakTrigger=$this->h-$margin;
1050
* Defines the way the document is to be displayed by the viewer. The zoom level can be set: pages can be displayed entirely on screen, occupy the full width of the window, use real size, be scaled by a specific zooming factor or use viewer default (configured in the Preferences menu of Acrobat). The page layout can be specified too: single at once, continuous display, two columns or viewer default. By default, documents use the full width mode with continuous display.
1051
* @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
1052
* @param string $layout The page layout. Possible values are:<ul><li>single: displays one page at once</li><li>continuous: displays pages continuously (default)</li><li>two: displays two pages on two columns</li><li>default: uses viewer default mode</li></ul>
1055
function SetDisplayMode($zoom, $layout='continuous') {
1056
//Set display mode in viewer
1057
if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
1058
$this->ZoomMode=$zoom;
1061
$this->Error('Incorrect zoom display mode: '.$zoom);
1063
if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') {
1064
$this->LayoutMode=$layout;
1067
$this->Error('Incorrect layout display mode: '.$layout);
1072
* Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
1073
* Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
1074
* @param boolean $compress Boolean indicating if compression must be enabled.
1077
function SetCompression($compress) {
1078
//Set page compression
1079
if(function_exists('gzcompress')) {
1080
$this->compress=$compress;
1083
$this->compress=false;
1088
* Defines the title of the document.
1089
* @param string $title The title.
1091
* @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
1093
function SetTitle($title) {
1095
$this->title=$title;
1099
* Defines the subject of the document.
1100
* @param string $subject The subject.
1102
* @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
1104
function SetSubject($subject) {
1105
//Subject of document
1106
$this->subject=$subject;
1110
* Defines the author of the document.
1111
* @param string $author The name of the author.
1113
* @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
1115
function SetAuthor($author) {
1116
//Author of document
1117
$this->author=$author;
1121
* Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
1122
* @param string $keywords The list of keywords.
1124
* @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
1126
function SetKeywords($keywords) {
1127
//Keywords of document
1128
$this->keywords=$keywords;
1132
* Defines the creator of the document. This is typically the name of the application that generates the PDF.
1133
* @param string $creator The name of the creator.
1135
* @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
1137
function SetCreator($creator) {
1138
//Creator of document
1139
$this->creator=$creator;
1143
* Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
1144
* <b>Example:</b><br />
1146
* class PDF extends TCPDF {
1147
* function Footer() {
1148
* //Go to 1.5 cm from bottom
1150
* //Select Arial italic 8
1151
* $this->SetFont('Arial','I',8);
1152
* //Print current and total page numbers
1153
* $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
1157
* $pdf->AliasNbPages();
1159
* @param string $alias The alias. Default value: {nb}.
1161
* @see PageNo(), Footer()
1163
function AliasNbPages($alias='{nb}') {
1164
//Define an alias for total number of pages
1165
$this->AliasNbPages = $this->_escapetext($alias);
1169
* This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
1170
* 2004-06-11 :: Nicola Asuni : changed bold tag with strong
1171
* @param string $msg The error message
1174
function Error($msg) {
1176
die('<strong>TCPDF error: </strong>'.$msg);
1180
* This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
1181
* Note: no page is created by this method
1183
* @see AddPage(), Close()
1191
* Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document.
1193
* @see Open(), Output()
1196
//Terminate document
1197
if($this->state==3) {
1200
if($this->page==0) {
1204
$this->InFooter=true;
1206
$this->InFooter=false;
1214
* Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer. Then the page is added, the current position set to the top-left corner according to the left and top margins, and Header() is called to display the header.
1215
* The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width.
1216
* The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
1217
* @param string $orientation Page orientation. Possible values are (case insensitive):<ul><li>P or Portrait</li><li>L or Landscape</li></ul> The default value is the one passed to the constructor.
1219
* @see TCPDF(), Header(), Footer(), SetMargins()
1221
function AddPage($orientation='') {
1223
if($this->state==0) {
1226
$family=$this->FontFamily;
1227
$style=$this->FontStyle.($this->underline ? 'U' : '');
1228
$size=$this->FontSizePt;
1229
$lw=$this->LineWidth;
1230
$dc=$this->DrawColor;
1231
$fc=$this->FillColor;
1232
$tc=$this->TextColor;
1233
$cf=$this->ColorFlag;
1236
$this->InFooter=true;
1238
$this->InFooter=false;
1243
$this->_beginpage($orientation);
1244
//Set line cap style to square
1247
$this->LineWidth=$lw;
1248
$this->_out(sprintf('%.2f w',$lw*$this->k));
1251
$this->SetFont($family,$style,$size);
1254
$this->DrawColor=$dc;
1258
$this->FillColor=$fc;
1262
$this->TextColor=$tc;
1263
$this->ColorFlag=$cf;
1266
//Restore line width
1267
if($this->LineWidth!=$lw) {
1268
$this->LineWidth=$lw;
1269
$this->_out(sprintf('%.2f w',$lw*$this->k));
1273
$this->SetFont($family,$style,$size);
1276
if($this->DrawColor!=$dc) {
1277
$this->DrawColor=$dc;
1280
if($this->FillColor!=$fc) {
1281
$this->FillColor=$fc;
1284
$this->TextColor=$tc;
1285
$this->ColorFlag=$cf;
1292
* @param string $ln header image logo
1293
* @param string $lw header image logo width in mm
1294
* @param string $ht string to print as title on document header
1295
* @param string $hs string to print on document header
1297
function setHeaderData($ln="", $lw=0, $ht="", $hs="") {
1298
$this->header_logo = $ln;
1299
$this->header_logo_width = $lw;
1300
$this->header_title = $ht;
1301
$this->header_string = $hs;
1305
* Set header margin.
1306
* (minimum distance between header and top page margin)
1307
* @param int $hm distance in millimeters
1309
function setHeaderMargin($hm=10) {
1310
$this->header_margin = $hm;
1314
* Set footer margin.
1315
* (minimum distance between footer and bottom page margin)
1316
* @param int $fm distance in millimeters
1318
function setFooterMargin($fm=10) {
1319
$this->footer_margin = $fm;
1323
* This method is used to render the page header.
1324
* It is automatically called by AddPage() and could be overwritten in your own inherited class.
1327
if ($this->print_header) {
1329
if (!isset($this->original_lMargin)) {
1330
$this->original_lMargin = $this->lMargin;
1332
if (!isset($this->original_rMargin)) {
1333
$this->original_rMargin = $this->rMargin;
1336
//set current position
1337
$this->SetXY($this->original_lMargin, $this->header_margin);
1339
if (($this->header_logo) AND ($this->header_logo != K_BLANK_IMAGE)) {
1340
$this->Image(K_PATH_IMAGES.$this->header_logo, $this->original_lMargin, $this->header_margin, $this->header_logo_width);
1343
$this->img_rb_y = $this->GetY();
1346
$cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2);
1348
$header_x = $this->original_lMargin + ($this->header_logo_width * 1.05); //set left margin for text data cell
1351
$this->SetFont($this->header_font[0], 'B', $this->header_font[2] + 1);
1352
$this->SetX($header_x);
1353
$this->Cell($this->header_width, $cell_height, $this->header_title, 0, 1, 'L');
1356
$this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
1357
$this->SetX($header_x);
1358
$this->MultiCell($this->header_width, $cell_height, $this->header_string, 0, 'L', 0);
1360
// print an ending header line
1361
if (empty($this->header_width)) {
1362
//set style for cell border
1363
$this->SetLineWidth(0.3);
1364
$this->SetDrawColor(0, 0, 0);
1365
$this->SetY(1 + max($this->img_rb_y, $this->GetY()));
1366
$this->SetX($this->original_lMargin);
1367
$this->Cell(0, 0, '', 'T', 0, 'C');
1371
$this->SetXY($this->original_lMargin, $this->tMargin);
1376
* This method is used to render the page footer.
1377
* It is automatically called by AddPage() and could be overwritten in your own inherited class.
1380
if ($this->print_footer) {
1382
if (!isset($this->original_lMargin)) {
1383
$this->original_lMargin = $this->lMargin;
1385
if (!isset($this->original_rMargin)) {
1386
$this->original_rMargin = $this->rMargin;
1390
$this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]);
1391
//set style for cell border
1393
$this->SetLineWidth($line_width);
1394
$this->SetDrawColor(0, 0, 0);
1396
$footer_height = round((K_CELL_HEIGHT_RATIO * $this->footer_font[2]) / $this->k, 2); //footer height
1397
//get footer y position
1398
$footer_y = $this->h - $this->footer_margin - $footer_height;
1399
//set current position
1400
$this->SetXY($this->original_lMargin, $footer_y);
1402
//print document barcode
1403
if ($this->barcode) {
1405
$barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin)); //max width
1406
$this->writeBarcode($this->original_lMargin, $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode);
1409
$this->SetXY($this->original_lMargin, $footer_y);
1412
$this->Cell(0, $footer_height, $this->l['w_page']." ".$this->PageNo().' / {nb}', 'T', 0, 'R');
1417
* Returns the current page number.
1418
* @return int page number
1420
* @see AliasNbPages()
1423
//Get current page number
1428
* Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
1429
* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1430
* @param int $g Green component (between 0 and 255)
1431
* @param int $b Blue component (between 0 and 255)
1433
* @see SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
1435
function SetDrawColor($r, $g=-1, $b=-1) {
1436
//Set color for all stroking operations
1437
if(($r==0 and $g==0 and $b==0) or $g==-1) {
1438
$this->DrawColor=sprintf('%.3f G',$r/255);
1441
$this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
1444
$this->_out($this->DrawColor);
1449
* Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
1450
* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1451
* @param int $g Green component (between 0 and 255)
1452
* @param int $b Blue component (between 0 and 255)
1453
* @param boolean $storeprev if true stores the RGB array on $prevFillColor variable.
1455
* @see SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
1457
function SetFillColor($r, $g=-1, $b=-1, $storeprev=false) {
1458
//Set color for all filling operations
1459
if(($r==0 and $g==0 and $b==0) or $g==-1) {
1460
$this->FillColor=sprintf('%.3f g',$r/255);
1463
$this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
1465
$this->ColorFlag=($this->FillColor!=$this->TextColor);
1467
$this->_out($this->FillColor);
1470
// store color as previous value
1471
$this->prevFillColor = array($r, $g, $b);
1476
* Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
1477
* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
1478
* @param int $g Green component (between 0 and 255)
1479
* @param int $b Blue component (between 0 and 255)
1480
* @param boolean $storeprev if true stores the RGB array on $prevTextColor variable.
1482
* @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
1484
function SetTextColor($r, $g=-1, $b=-1, $storeprev=false) {
1485
//Set color for text
1486
if(($r==0 and $g==0 and $b==0) or $g==-1) {
1487
$this->TextColor=sprintf('%.3f g',$r/255);
1490
$this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
1492
$this->ColorFlag=($this->FillColor!=$this->TextColor);
1494
// store color as previous value
1495
$this->prevTextColor = array($r, $g, $b);
1500
* Returns the length of a string in user unit. A font must be selected.<br>
1501
* Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]
1502
* @param string $s The string whose length is to be computed
1506
function GetStringWidth($s) {
1507
//Get width of a string in the current font
1509
$cw = &$this->CurrentFont['cw'];
1511
if($this->isunicode) {
1512
$unicode = $this->UTF8StringToArray($s);
1513
foreach($unicode as $char) {
1514
if (isset($cw[$char])) {
1516
} elseif(isset($cw[ord($char)])) {
1517
$w+=$cw[ord($char)];
1518
} elseif(isset($cw[chr($char)])) {
1519
$w+=$cw[chr($char)];
1520
} elseif(isset($this->CurrentFont['desc']['MissingWidth'])) {
1521
$w += $this->CurrentFont['desc']['MissingWidth']; // set default size
1528
for($i=0; $i<$l; $i++) {
1529
if (isset($cw[$s{$i}])) {
1531
} else if (isset($cw[ord($s{$i})])) {
1532
$w += $cw[ord($s{$i})];
1536
return ($w * $this->FontSize / 1000);
1540
* Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
1541
* @param float $width The width.
1543
* @see Line(), Rect(), Cell(), MultiCell()
1545
function SetLineWidth($width) {
1547
$this->LineWidth=$width;
1549
$this->_out(sprintf('%.2f w',$width*$this->k));
1554
* Draws a line between two points.
1555
* @param float $x1 Abscissa of first point
1556
* @param float $y1 Ordinate of first point
1557
* @param float $x2 Abscissa of second point
1558
* @param float $y2 Ordinate of second point
1560
* @see SetLineWidth(), SetDrawColor()
1562
function Line($x1, $y1, $x2, $y2) {
1564
$this->_out(sprintf('%.2f %.2f m %.2f %.2f l S', $x1*$this->k, ($this->h-$y1)*$this->k, $x2*$this->k, ($this->h-$y2)*$this->k));
1568
* Outputs a rectangle. It can be drawn (border only), filled (with no border) or both.
1569
* @param float $x Abscissa of upper-left corner
1570
* @param float $y Ordinate of upper-left corner
1571
* @param float $w Width
1572
* @param float $h Height
1573
* @param string $style Style of rendering. Possible values are:<ul><li>D or empty string: draw (default)</li><li>F: fill</li><li>DF or FD: draw and fill</li></ul>
1575
* @see SetLineWidth(), SetDrawColor(), SetFillColor()
1577
function Rect($x, $y, $w, $h, $style='') {
1582
elseif($style=='FD' or $style=='DF') {
1588
$this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
1592
* Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility. The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by FPDF_FONTPATH if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
1593
* Support UTF-8 Unicode [Nicola Asuni, 2005-01-02].
1594
* <b>Example</b>:<br />
1596
* $pdf->AddFont('Comic','I');
1597
* // is equivalent to:
1598
* $pdf->AddFont('Comic','I','comici.php');
1600
* @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
1601
* @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
1602
* @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no space.
1606
function AddFont($family, $style='', $file='') {
1607
if(empty($family)) {
1611
//Add a TrueType or Type1 font
1612
$family = strtolower($family);
1613
if((!$this->isunicode) AND ($family == 'arial')) {
1614
$family = 'helvetica';
1617
$style=strtoupper($style);
1618
$style=str_replace('U','',$style);
1619
if($style == 'IB') {
1623
$fontkey = $family.$style;
1624
// check if the font has been already added
1625
if(isset($this->fonts[$fontkey])) {
1630
$file = str_replace(' ', '', $family).strtolower($style).'.php';
1632
if(!file_exists($this->_getfontpath().$file)) {
1633
// try to load the basic file without styles
1634
$file = str_replace(' ', '', $family).'.php';
1637
include($this->_getfontpath().$file);
1639
if(!isset($name) AND !isset($fpdf_charwidths)) {
1640
$this->Error('Could not include font definition file');
1643
$i = count($this->fonts)+1;
1645
if($this->isunicode) {
1646
$this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg);
1647
$fpdf_charwidths[$fontkey] = $cw;
1649
$this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]);
1652
if(isset($diff) AND (!empty($diff))) {
1653
//Search existing encodings
1655
$nb=count($this->diffs);
1656
for($i=1;$i<=$nb;$i++) {
1657
if($this->diffs[$i]==$diff) {
1664
$this->diffs[$d]=$diff;
1666
$this->fonts[$fontkey]['diff']=$d;
1669
if((strcasecmp($type,"TrueType") == 0) OR (strcasecmp($type,"TrueTypeUnicode") == 0)) {
1670
$this->FontFiles[$file]=array('length1'=>$originalsize);
1673
$this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
1679
* Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid.
1680
* The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
1681
* The method can be called before the first page is created and the font is retained from page to page.
1682
If you just wish to change the current font size, it is simpler to call SetFontSize().
1683
* Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the FPDF_FONTPATH constant</li></ul><br />
1684
* Example for the last case (note the trailing slash):<br />
1686
* define('FPDF_FONTPATH','/home/www/font/');
1687
* require('tcpdf.php');
1689
* //Times regular 12
1690
* $pdf->SetFont('Times');
1692
* $pdf->SetFont('Arial','B',14);
1694
* $pdf->SetFont('');
1695
* //Times bold, italic and underlined 14
1696
* $pdf->SetFont('Times','BIU');
1698
* If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated.
1699
* @param string $family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained.
1700
* @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li></ul>or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats
1701
* @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
1703
* @see AddFont(), SetFontSize(), Cell(), MultiCell(), Write()
1705
function SetFont($family, $style='', $size=0) {
1706
// save previous values
1707
$this->prevFontFamily = $this->FontFamily;
1708
$this->prevFontStyle = $this->FontStyle;
1710
//Select a font; size given in points
1711
global $fpdf_charwidths;
1713
$family=strtolower($family);
1715
$family=$this->FontFamily;
1717
if((!$this->isunicode) AND ($family == 'arial')) {
1718
$family = 'helvetica';
1720
elseif(($family=="symbol") OR ($family=="zapfdingbats")) {
1723
$style=strtoupper($style);
1725
if(strpos($style,'U')!==false) {
1726
$this->underline=true;
1727
$style=str_replace('U','',$style);
1730
$this->underline=false;
1736
$size=$this->FontSizePt;
1739
// try to add font (if not already added)
1740
if($this->isunicode) {
1741
$this->AddFont($family, $style);
1744
//Test if font is already selected
1745
if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size)) {
1749
$fontkey = $family.$style;
1750
//if(!isset($this->fonts[$fontkey]) AND isset($this->fonts[$family])) {
1754
//Test if used for the first time
1755
if(!isset($this->fonts[$fontkey])) {
1756
//Check if one of the standard fonts
1757
if(isset($this->CoreFonts[$fontkey])) {
1758
if(!isset($fpdf_charwidths[$fontkey])) {
1761
if(($family!='symbol') AND ($family!='zapfdingbats')) {
1762
$file .= strtolower($style);
1764
if(!file_exists($this->_getfontpath().$file.'.php')) {
1765
// try to load the basic file without styles
1769
include($this->_getfontpath().$file.'.php');
1770
if (($this->isunicode AND !isset($ctg)) OR ((!$this->isunicode) AND (!isset($fpdf_charwidths[$fontkey]))) ) {
1771
$this->Error("Could not include font metric file [".$fontkey."]: ".$this->_getfontpath().$file.".php");
1774
$i = count($this->fonts) + 1;
1776
if($this->isunicode) {
1777
$this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg);
1778
$fpdf_charwidths[$fontkey] = $cw;
1780
$this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]);
1784
$this->Error('Undefined font: '.$family.' '.$style);
1788
$this->FontFamily = $family;
1789
$this->FontStyle = $style;
1790
$this->FontSizePt = $size;
1791
$this->FontSize = $size / $this->k;
1792
$this->CurrentFont = &$this->fonts[$fontkey];
1794
$this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
1799
* Defines the size of the current font.
1800
* @param float $size The size (in points)
1804
function SetFontSize($size) {
1805
//Set font size in points
1806
if($this->FontSizePt==$size) {
1809
$this->FontSizePt = $size;
1810
$this->FontSize = $size / $this->k;
1811
if($this->page > 0) {
1812
$this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
1817
* 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 />
1818
* The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
1820
* @see Cell(), Write(), Image(), Link(), SetLink()
1822
function AddLink() {
1823
//Create a new internal link
1824
$n=count($this->links)+1;
1825
$this->links[$n]=array(0,0);
1830
* Defines the page and position a link points to
1831
* @param int $link The link identifier returned by AddLink()
1832
* @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
1833
* @param int $page Number of target page; -1 indicates the current page. This is the default value
1837
function SetLink($link, $y=0, $page=-1) {
1838
//Set destination of internal link
1845
$this->links[$link]=array($page,$y);
1849
* 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.
1850
* @param float $x Abscissa of the upper-left corner of the rectangle
1851
* @param float $y Ordinate of the upper-left corner of the rectangle
1852
* @param float $w Width of the rectangle
1853
* @param float $h Height of the rectangle
1854
* @param mixed $link URL or identifier returned by AddLink()
1856
* @see AddLink(), Cell(), Write(), Image()
1858
function Link($x, $y, $w, $h, $link) {
1859
//Put a link on the page
1860
$this->PageLinks[$this->page][] = array($x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h*$this->k, $link);
1864
* 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.
1865
* @param float $x Abscissa of the origin
1866
* @param float $y Ordinate of the origin
1867
* @param string $txt String to print
1869
* @see SetFont(), SetTextColor(), Cell(), MultiCell(), Write()
1871
function Text($x, $y, $txt) {
1873
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET', $x * $this->k, ($this->h-$y) * $this->k, $this->_escapetext($txt));
1874
if($this->underline AND ($txt!='')) {
1875
$s .= ' '.$this->_dounderline($x,$y,$txt);
1877
if($this->ColorFlag) {
1878
$s='q '.$this->TextColor.' '.$s.' Q';
1884
* 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 />
1885
* This method is called automatically and should not be called directly by the application.<br />
1886
* <b>Example:</b><br />
1887
* The method is overriden in an inherited class in order to obtain a 3 column layout:<br />
1889
* class PDF extends TCPDF {
1892
* function SetCol($col) {
1893
* //Move position to a column
1896
* $this->SetLeftMargin($x);
1900
* function AcceptPageBreak() {
1901
* if($this->col<2) {
1902
* //Go to next column
1903
* $this->SetCol($this->col+1);
1908
* //Go back to first column and issue page break
1918
* $pdf->SetFont('Arial','',12);
1919
* for($i=1;$i<=300;$i++) {
1920
* $pdf->Cell(0,5,"Line $i",0,1);
1926
* @see SetAutoPageBreak()
1928
function AcceptPageBreak() {
1929
//Accept automatic page break or not
1930
return $this->AutoPageBreak;
1934
* 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 />
1935
* If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
1936
* @param float $w Cell width. If 0, the cell extends up to the right margin.
1937
* @param float $h Cell height. Default value: 0.
1938
* @param string $txt String to print. Default value: empty string.
1939
* @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>
1940
* @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>
1941
Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
1942
* @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>
1943
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1944
* @param mixed $link URL or identifier returned by AddLink().
1946
* @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
1948
function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='') {
1951
if(($this->y + $h) > $this->PageBreakTrigger AND empty($this->InFooter) AND $this->AcceptPageBreak()) {
1952
//Automatic page break
1957
$this->_out('0 Tw');
1959
$this->AddPage($this->CurOrientation);
1963
$this->_out(sprintf('%.3f Tw',$ws * $k));
1967
$w = $this->w - $this->rMargin - $this->x;
1970
if(($fill == 1) OR ($border == 1)) {
1972
$op = ($border == 1) ? 'B' : 'f';
1977
$s = sprintf('%.2f %.2f %.2f %.2f re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op);
1979
if(is_string($border)) {
1982
if(strpos($border,'L')!==false) {
1983
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
1985
if(strpos($border,'T')!==false) {
1986
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
1988
if(strpos($border,'R')!==false) {
1989
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
1991
if(strpos($border,'B')!==false) {
1992
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
1996
$width = $this->GetStringWidth($txt);
1998
$dx = $w - $this->cMargin - $width;
2000
elseif($align=='C') {
2001
$dx = ($w - $width)/2;
2004
$dx = $this->cMargin;
2006
if($this->ColorFlag) {
2007
$s .= 'q '.$this->TextColor.' ';
2009
$txt2 = $this->_escapetext($txt);
2010
$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);
2011
if($this->underline) {
2012
$s.=' '.$this->_dounderline($this->x + $dx, $this->y + 0.5 * $h + 0.3 * $this->FontSize, $txt);
2014
if($this->ColorFlag) {
2018
$this->Link($this->x + $dx, $this->y + 0.5 * $h - 0.5 * $this->FontSize, $width, $this->FontSize, $link);
2029
$this->x = $this->lMargin;
2038
* 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 />
2039
* Text can be aligned, centered or justified. The cell block can be framed and the background painted.
2040
* @param float $w Width of cells. If 0, they extend up to the right margin of the page.
2041
* @param float $h Height of cells.
2042
* @param string $txt String to print
2043
* @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>
2044
* @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>
2045
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
2047
* @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
2049
function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0) {
2050
//Output text with automatic or explicit line breaks
2051
$cw = &$this->CurrentFont['cw'];
2054
$w = $this->w - $this->rMargin - $this->x;
2057
$wmax = ($w - 2 * $this->cMargin);
2059
$s = str_replace("\r", '', $txt); // remove carriage returns
2071
if(strpos($border,'L')!==false) {
2074
if(strpos($border,'R')!==false) {
2077
$b=(strpos($border,'T')!==false) ? $b2.'T' : $b2;
2087
//Get next character
2089
if(preg_match("/[\n]/u", $c)) {
2090
//Explicit line break
2093
$this->_out('0 Tw');
2095
$this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
2102
if($border and $nl==2) {
2107
if(preg_match("/[ ]/u", $c)) {
2113
$l = $this->GetStringWidth(substr($s, $j, $i-$j));
2116
//Automatic line break
2123
$this->_out('0 Tw');
2125
$this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
2129
$this->ws = ($ns>1) ? ($wmax-$ls)/($ns-1) : 0;
2130
$this->_out(sprintf('%.3f Tw', $this->ws * $this->k));
2132
$this->Cell($w, $h, substr($s, $j, $sep-$j), $b, 2, $align, $fill);
2140
if($border AND ($nl==2)) {
2151
$this->_out('0 Tw');
2153
if($border and is_int(strpos($border,'B'))) {
2156
$this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
2157
$this->x=$this->lMargin;
2161
* 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 />
2162
* <b>Example:</b><br />
2164
* //Begin with regular font
2165
* $pdf->SetFont('Arial','',14);
2166
* $pdf->Write(5,'Visit ');
2167
* //Then put a blue underlined link
2168
* $pdf->SetTextColor(0,0,255);
2169
* $pdf->SetFont('','U');
2170
* $pdf->Write(5,'www.tecnick.com','http://www.tecnick.com');
2172
* @param float $h Line height
2173
* @param string $txt String to print
2174
* @param mixed $link URL or identifier returned by AddLink()
2175
* @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
2177
* @see SetFont(), SetTextColor(), AddLink(), MultiCell(), SetAutoPageBreak()
2179
function Write($h, $txt, $link='', $fill=0) {
2181
//Output text in flowing mode
2182
$cw = &$this->CurrentFont['cw'];
2183
$w = $this->w - $this->rMargin - $this->x;
2184
$wmax = ($w - 2 * $this->cMargin);
2186
$s = str_replace("\r", '', $txt);
2189
// handle single space character
2190
if(($nb==1) AND preg_match("/[ ]/u", $s)) {
2191
$this->x += $this->GetStringWidth($s);
2201
//Get next character
2203
if(preg_match("/[\n]/u", $c)) {
2204
//Explicit line break
2205
$this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link);
2211
$this->x = $this->lMargin;
2212
$w = $this->w - $this->rMargin - $this->x;
2213
$wmax = ($w - 2 * $this->cMargin);
2218
if(preg_match("/[ ]/u", $c)) {
2222
$l = $this->GetStringWidth(substr($s, $j, $i-$j));
2225
//Automatic line break (word wrapping)
2227
if($this->x > $this->lMargin) {
2229
$this->x = $this->lMargin;
2231
$w=$this->w - $this->rMargin - $this->x;
2232
$wmax=($w - 2 * $this->cMargin);
2240
$this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link);
2243
$this->Cell($w, $h, substr($s, $j, $sep-$j), 0, 2, '', $fill, $link);
2250
$this->x = $this->lMargin;
2251
$w = $this->w - $this->rMargin - $this->x;
2252
$wmax = ($w - 2 * $this->cMargin);
2263
$this->Cell($this->GetStringWidth(substr($s, $j)), $h, substr($s, $j), 0, 0, '', $fill, $link);
2268
* 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>
2269
* Supported formats are JPEG and PNG.
2270
* For JPEG, all flavors are allowed:<ul><li>gray scales</li><li>true colors (24 bits)</li><li>CMYK (32 bits)</li></ul>
2271
* 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>
2272
* but are not supported:<ul><li>Interlacing</li><li>Alpha channel</li></ul>
2273
* If a transparent color is defined, it will be taken into account (but will be only interpreted by Acrobat 4 and above).<br />
2274
* The format can be specified explicitly or inferred from the file extension.<br />
2275
* It is possible to put a link on the image.<br />
2276
* Remark: if an image is used several times, only one copy will be embedded in the file.<br />
2277
* @param string $file Name of the file containing the image.
2278
* @param float $x Abscissa of the upper-left corner.
2279
* @param float $y Ordinate of the upper-left corner.
2280
* @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
2281
* @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
2282
* @param string $type Image format. Possible values are (case insensitive): JPG, JPEG, PNG. If not specified, the type is inferred from the file extension.
2283
* @param mixed $link URL or identifier returned by AddLink().
2287
function Image($file, $x, $y, $w=0, $h=0, $type='', $link='') {
2288
//Put an image on the page
2289
if(!isset($this->images[$file])) {
2290
//First use of image, get info
2292
$pos = strrpos($file,'.');
2294
$this->Error('Image file has no extension and no type was specified: '.$file);
2296
$type = substr($file, $pos+1);
2298
$type = strtolower($type);
2299
$mqr = get_magic_quotes_runtime();
2300
set_magic_quotes_runtime(0);
2301
if($type == 'jpg' or $type == 'jpeg') {
2302
$info=$this->_parsejpg($file);
2304
elseif($type == 'png') {
2305
$info=$this->_parsepng($file);
2308
//Allow for additional formats
2309
$mtd='_parse'.$type;
2310
if(!method_exists($this,$mtd)) {
2311
$this->Error('Unsupported image type: '.$type);
2313
$info=$this->$mtd($file);
2315
set_magic_quotes_runtime($mqr);
2316
$info['i']=count($this->images)+1;
2317
$this->images[$file]=$info;
2320
$info=$this->images[$file];
2322
//Automatic width and height calculation if needed
2323
if(($w == 0) and ($h == 0)) {
2324
//Put image at 72 dpi
2325
// 2004-06-14 :: Nicola Asuni, scale factor where added
2326
$w = $info['w'] / ($this->imgscale * $this->k);
2327
$h = $info['h'] / ($this->imgscale * $this->k);
2330
$w = $h * $info['w'] / $info['h'];
2333
$h = $w * $info['h'] / $info['w'];
2335
$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']));
2337
$this->Link($x, $y, $w, $h, $link);
2340
//2002-07-31 - Nicola Asuni
2341
// set right-bottom corner coordinates
2342
$this->img_rb_x = $x + $w;
2343
$this->img_rb_y = $y + $h;
2347
* Performs a line break. The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
2348
* @param float $h The height of the break. By default, the value equals the height of the last printed cell.
2352
function Ln($h='') {
2353
//Line feed; default value is last cell height
2354
$this->x=$this->lMargin;
2356
$this->y+=$this->lasth;
2364
* Returns the abscissa of the current position.
2367
* @see SetX(), GetY(), SetY()
2375
* Defines the abscissa of the current position. If the passed value is negative, it is relative to the right of the page.
2376
* @param float $x The value of the abscissa.
2378
* @see GetX(), GetY(), SetY(), SetXY()
2386
$this->x=$this->w+$x;
2391
* Returns the ordinate of the current position.
2394
* @see SetY(), GetX(), SetX()
2402
* 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.
2403
* @param float $y The value of the ordinate.
2405
* @see GetX(), GetY(), SetY(), SetXY()
2408
//Set y position and reset x
2409
$this->x=$this->lMargin;
2414
$this->y=$this->h+$y;
2419
* 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.
2420
* @param float $x The value of the abscissa
2421
* @param float $y The value of the ordinate
2423
* @see SetX(), SetY()
2425
function SetXY($x, $y) {
2426
//Set x and y positions
2432
* 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 />
2433
* The method first calls Close() if necessary to terminate the document.
2434
* @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.
2435
* @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).
2439
function Output($name='',$dest='') {
2440
//Output PDF to some destination
2441
//Finish document if necessary
2442
if($this->state < 3) {
2445
//Normalize parameters
2446
if(is_bool($dest)) {
2447
$dest=$dest ? 'D' : 'F';
2449
$dest=strtoupper($dest);
2460
//Send to standard output
2461
if(ob_get_contents()) {
2462
$this->Error('Some data has already been output, can\'t send PDF file');
2464
if(php_sapi_name()!='cli') {
2465
//We send to a browser
2466
header('Content-Type: application/pdf');
2467
if(headers_sent()) {
2468
$this->Error('Some data has already been output to browser, can\'t send PDF file');
2470
header('Content-Length: '.strlen($this->buffer));
2471
header('Content-disposition: inline; filename="'.$name.'"');
2478
if(ob_get_contents()) {
2479
$this->Error('Some data has already been output, can\'t send PDF file');
2481
if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) {
2482
header('Content-Type: application/force-download');
2484
header('Content-Type: application/octet-stream');
2486
if(headers_sent()) {
2487
$this->Error('Some data has already been output to browser, can\'t send PDF file');
2489
header('Content-Length: '.strlen($this->buffer));
2490
header('Content-disposition: attachment; filename="'.$name.'"');
2495
//Save to local file
2496
$f=fopen($name,'wb');
2498
$this->Error('Unable to create output file: '.$name);
2500
fwrite($f,$this->buffer,strlen($this->buffer));
2505
//Return as a string
2506
return $this->buffer;
2509
$this->Error('Incorrect output destination: '.$dest);
2518
* Check for locale-related bug
2521
function _dochecks() {
2522
//Check for locale-related bug
2524
$this->Error('Don\'t alter the locale before including class file');
2526
//Check for decimal separator
2527
if(sprintf('%.1f',1.0)!='1.0') {
2528
setlocale(LC_NUMERIC,'C');
2536
function _getfontpath() {
2537
if(!defined('FPDF_FONTPATH') AND is_dir(dirname(__FILE__).'/font')) {
2538
define('FPDF_FONTPATH', dirname(__FILE__).'/font/');
2540
return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : '';
2547
function _begindoc() {
2550
$this->_out('%PDF-1.3');
2557
function _putpages() {
2559
if(!empty($this->AliasNbPages)) {
2560
$nbstr = $this->UTF8ToUTF16BE($nb, false);
2561
//Replace number of pages
2562
for($n=1;$n<=$nb;$n++) {
2563
$this->pages[$n]=str_replace($this->AliasNbPages, $nbstr, $this->pages[$n]);
2566
if($this->DefOrientation=='P') {
2574
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
2575
for($n=1;$n<=$nb;$n++) {
2578
$this->_out('<</Type /Page');
2579
$this->_out('/Parent 1 0 R');
2580
if(isset($this->OrientationChanges[$n])) {
2581
$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt));
2583
$this->_out('/Resources 2 0 R');
2584
if(isset($this->PageLinks[$n])) {
2586
$annots='/Annots [';
2587
foreach($this->PageLinks[$n] as $pl) {
2588
$rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
2589
$annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
2590
if(is_string($pl[4])) {
2591
$annots.='/A <</S /URI /URI ('.$this->_escape($pl[4]).')>>>>';
2594
$l=$this->links[$pl[4]];
2595
$h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt;
2596
$annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k);
2599
$this->_out($annots.']');
2601
$this->_out('/Contents '.($this->n+1).' 0 R>>');
2602
$this->_out('endobj');
2604
$p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n];
2606
$this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
2607
$this->_putstream($p);
2608
$this->_out('endobj');
2611
$this->offsets[1]=strlen($this->buffer);
2612
$this->_out('1 0 obj');
2613
$this->_out('<</Type /Pages');
2615
for($i=0;$i<$nb;$i++) {
2616
$kids.=(3+2*$i).' 0 R ';
2618
$this->_out($kids.']');
2619
$this->_out('/Count '.$nb);
2620
$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt));
2622
$this->_out('endobj');
2630
function _putfonts() {
2632
foreach($this->diffs as $diff) {
2635
$this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
2636
$this->_out('endobj');
2638
$mqr=get_magic_quotes_runtime();
2639
set_magic_quotes_runtime(0);
2640
foreach($this->FontFiles as $file=>$info) {
2641
//Font file embedding
2643
$this->FontFiles[$file]['n']=$this->n;
2645
$f=fopen($this->_getfontpath().$file,'rb',1);
2647
$this->Error('Font file not found');
2650
$font .= fread($f, 8192);
2653
$compressed=(substr($file,-2)=='.z');
2654
if(!$compressed && isset($info['length2'])) {
2655
$header=(ord($font{0})==128);
2657
//Strip first binary header
2658
$font=substr($font,6);
2660
if($header && ord($font{$info['length1']})==128) {
2661
//Strip second binary header
2662
$font=substr($font,0,$info['length1']).substr($font,$info['length1']+6);
2665
$this->_out('<</Length '.strlen($font));
2667
$this->_out('/Filter /FlateDecode');
2669
$this->_out('/Length1 '.$info['length1']);
2670
if(isset($info['length2'])) {
2671
$this->_out('/Length2 '.$info['length2'].' /Length3 0');
2674
$this->_putstream($font);
2675
$this->_out('endobj');
2677
set_magic_quotes_runtime($mqr);
2678
foreach($this->fonts as $k=>$font) {
2680
$this->fonts[$k]['n']=$this->n+1;
2681
$type=$font['type'];
2682
$name=$font['name'];
2686
$this->_out('<</Type /Font');
2687
$this->_out('/BaseFont /'.$name);
2688
$this->_out('/Subtype /Type1');
2689
if($name!='Symbol' && $name!='ZapfDingbats') {
2690
$this->_out('/Encoding /WinAnsiEncoding');
2693
$this->_out('endobj');
2694
} elseif($type=='Type1' || $type=='TrueType') {
2695
//Additional Type1 or TrueType font
2697
$this->_out('<</Type /Font');
2698
$this->_out('/BaseFont /'.$name);
2699
$this->_out('/Subtype /'.$type);
2700
$this->_out('/FirstChar 32 /LastChar 255');
2701
$this->_out('/Widths '.($this->n+1).' 0 R');
2702
$this->_out('/FontDescriptor '.($this->n+2).' 0 R');
2704
if(isset($font['diff'])) {
2705
$this->_out('/Encoding '.($nf+$font['diff']).' 0 R');
2707
$this->_out('/Encoding /WinAnsiEncoding');
2711
$this->_out('endobj');
2716
for($i=32;$i<=255;$i++) {
2717
$s.=$cw[chr($i)].' ';
2719
$this->_out($s.']');
2720
$this->_out('endobj');
2723
$s='<</Type /FontDescriptor /FontName /'.$name;
2724
foreach($font['desc'] as $k=>$v) {
2727
$file = $font['file'];
2729
$s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
2731
$this->_out($s.'>>');
2732
$this->_out('endobj');
2734
//Allow for additional types
2735
$mtd='_put'.strtolower($type);
2736
if(!method_exists($this, $mtd)) {
2737
$this->Error('Unsupported font type: '.$type);
2748
function _putimages() {
2749
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
2750
reset($this->images);
2751
while(list($file,$info)=each($this->images)) {
2753
$this->images[$file]['n']=$this->n;
2754
$this->_out('<</Type /XObject');
2755
$this->_out('/Subtype /Image');
2756
$this->_out('/Width '.$info['w']);
2757
$this->_out('/Height '.$info['h']);
2758
if($info['cs']=='Indexed') {
2759
$this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
2762
$this->_out('/ColorSpace /'.$info['cs']);
2763
if($info['cs']=='DeviceCMYK') {
2764
$this->_out('/Decode [1 0 1 0 1 0 1 0]');
2767
$this->_out('/BitsPerComponent '.$info['bpc']);
2768
if(isset($info['f'])) {
2769
$this->_out('/Filter /'.$info['f']);
2771
if(isset($info['parms'])) {
2772
$this->_out($info['parms']);
2774
if(isset($info['trns']) and is_array($info['trns'])) {
2776
for($i=0;$i<count($info['trns']);$i++) {
2777
$trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
2779
$this->_out('/Mask ['.$trns.']');
2781
$this->_out('/Length '.strlen($info['data']).'>>');
2782
$this->_putstream($info['data']);
2783
unset($this->images[$file]['data']);
2784
$this->_out('endobj');
2786
if($info['cs']=='Indexed') {
2788
$pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
2789
$this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
2790
$this->_putstream($pal);
2791
$this->_out('endobj');
2800
function _putxobjectdict() {
2801
foreach($this->images as $image) {
2802
$this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
2810
function _putresourcedict(){
2811
$this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
2812
$this->_out('/Font <<');
2813
foreach($this->fonts as $font) {
2814
$this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
2817
$this->_out('/XObject <<');
2818
$this->_putxobjectdict();
2826
function _putresources() {
2828
$this->_putimages();
2829
//Resource dictionary
2830
$this->offsets[2]=strlen($this->buffer);
2831
$this->_out('2 0 obj');
2833
$this->_putresourcedict();
2835
$this->_out('endobj');
2842
function _putinfo() {
2843
$this->_out('/Producer '.$this->_textstring(PDF_PRODUCER));
2844
if(!empty($this->title)) {
2845
$this->_out('/Title '.$this->_textstring($this->title));
2847
if(!empty($this->subject)) {
2848
$this->_out('/Subject '.$this->_textstring($this->subject));
2850
if(!empty($this->author)) {
2851
$this->_out('/Author '.$this->_textstring($this->author));
2853
if(!empty($this->keywords)) {
2854
$this->_out('/Keywords '.$this->_textstring($this->keywords));
2856
if(!empty($this->creator)) {
2857
$this->_out('/Creator '.$this->_textstring($this->creator));
2859
$this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis')));
2866
function _putcatalog() {
2867
$this->_out('/Type /Catalog');
2868
$this->_out('/Pages 1 0 R');
2869
if($this->ZoomMode=='fullpage') {
2870
$this->_out('/OpenAction [3 0 R /Fit]');
2872
elseif($this->ZoomMode=='fullwidth') {
2873
$this->_out('/OpenAction [3 0 R /FitH null]');
2875
elseif($this->ZoomMode=='real') {
2876
$this->_out('/OpenAction [3 0 R /XYZ null null 1]');
2878
elseif(!is_string($this->ZoomMode)) {
2879
$this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
2881
if($this->LayoutMode=='single') {
2882
$this->_out('/PageLayout /SinglePage');
2884
elseif($this->LayoutMode=='continuous') {
2885
$this->_out('/PageLayout /OneColumn');
2887
elseif($this->LayoutMode=='two') {
2888
$this->_out('/PageLayout /TwoColumnLeft');
2896
function _puttrailer() {
2897
$this->_out('/Size '.($this->n+1));
2898
$this->_out('/Root '.$this->n.' 0 R');
2899
$this->_out('/Info '.($this->n-1).' 0 R');
2906
function _putheader() {
2907
$this->_out('%PDF-'.$this->PDFVersion);
2914
function _enddoc() {
2915
$this->_putheader();
2917
$this->_putresources();
2923
$this->_out('endobj');
2927
$this->_putcatalog();
2929
$this->_out('endobj');
2931
$o=strlen($this->buffer);
2932
$this->_out('xref');
2933
$this->_out('0 '.($this->n+1));
2934
$this->_out('0000000000 65535 f ');
2935
for($i=1;$i<=$this->n;$i++) {
2936
$this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
2939
$this->_out('trailer');
2941
$this->_puttrailer();
2943
$this->_out('startxref');
2945
$this->_out('%%EOF');
2953
function _beginpage($orientation) {
2955
$this->pages[$this->page]='';
2957
$this->x=$this->lMargin;
2958
$this->y=$this->tMargin;
2959
$this->FontFamily='';
2961
if(empty($orientation)) {
2962
$orientation=$this->DefOrientation;
2965
$orientation=strtoupper($orientation{0});
2966
if($orientation!=$this->DefOrientation) {
2967
$this->OrientationChanges[$this->page]=true;
2970
if($orientation!=$this->CurOrientation) {
2971
//Change orientation
2972
if($orientation=='P') {
2973
$this->wPt=$this->fwPt;
2974
$this->hPt=$this->fhPt;
2979
$this->wPt=$this->fhPt;
2980
$this->hPt=$this->fwPt;
2984
$this->PageBreakTrigger=$this->h-$this->bMargin;
2985
$this->CurOrientation=$orientation;
2990
* End of page contents
2993
function _endpage() {
2998
* Begin a new object
3001
function _newobj() {
3003
$this->offsets[$this->n]=strlen($this->buffer);
3004
$this->_out($this->n.' 0 obj');
3011
function _dounderline($x,$y,$txt) {
3012
$up = $this->CurrentFont['up'];
3013
$ut = $this->CurrentFont['ut'];
3014
$w = $this->GetStringWidth($txt) + $this->ws * substr_count($txt,' ');
3015
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);
3019
* Extract info from a JPEG file
3022
function _parsejpg($file) {
3023
$a=GetImageSize($file);
3025
$this->Error('Missing or incorrect image file: '.$file);
3028
$this->Error('Not a JPEG file: '.$file);
3030
if(!isset($a['channels']) or $a['channels']==3) {
3031
$colspace='DeviceRGB';
3033
elseif($a['channels']==4) {
3034
$colspace='DeviceCMYK';
3037
$colspace='DeviceGray';
3039
$bpc=isset($a['bits']) ? $a['bits'] : 8;
3041
$f=fopen($file,'rb');
3044
$data.=fread($f,4096);
3047
return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
3051
* Extract info from a PNG file
3054
function _parsepng($file) {
3055
$f=fopen($file,'rb');
3057
$this->Error('Can\'t open image file: '.$file);
3060
if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
3061
$this->Error('Not a PNG file: '.$file);
3065
if(fread($f,4)!='IHDR') {
3066
$this->Error('Incorrect PNG file: '.$file);
3068
$w=$this->_freadint($f);
3069
$h=$this->_freadint($f);
3070
$bpc=ord(fread($f,1));
3072
$this->Error('16-bit depth not supported: '.$file);
3074
$ct=ord(fread($f,1));
3076
$colspace='DeviceGray';
3079
$colspace='DeviceRGB';
3082
$colspace='Indexed';
3085
$this->Error('Alpha channel not supported: '.$file);
3087
if(ord(fread($f,1))!=0) {
3088
$this->Error('Unknown compression method: '.$file);
3090
if(ord(fread($f,1))!=0) {
3091
$this->Error('Unknown filter method: '.$file);
3093
if(ord(fread($f,1))!=0) {
3094
$this->Error('Interlacing not supported: '.$file);
3097
$parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
3098
//Scan chunks looking for palette, transparency and image data
3103
$n=$this->_freadint($f);
3110
elseif($type=='tRNS') {
3111
//Read transparency info
3114
$trns=array(ord(substr($t,1,1)));
3117
$trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
3120
$pos=strpos($t,chr(0));
3127
elseif($type=='IDAT') {
3128
//Read image data block
3129
$data.=fread($f,$n);
3132
elseif($type=='IEND') {
3140
if($colspace=='Indexed' and empty($pal)) {
3141
$this->Error('Missing palette in '.$file);
3144
return array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'parms'=>$parms, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data);
3148
* Read a 4-byte integer from file
3151
function _freadint($f) {
3152
//Read a 4-byte integer from file
3153
$a=unpack('Ni',fread($f,4));
3158
* Format a text string
3161
function _textstring($s) {
3162
if($this->isunicode) {
3163
//Convert string to UTF-16BE
3164
$s = $this->UTF8ToUTF16BE($s, true);
3166
return '('. $this->_escape($s).')';
3170
* Format a text string
3173
function _escapetext($s) {
3174
if($this->isunicode) {
3175
//Convert string to UTF-16BE
3176
$s = $this->UTF8ToUTF16BE($s, false);
3178
return $this->_escape($s);
3182
* Add \ before \, ( and )
3185
function _escape($s) {
3186
// the chr(13) substitution fixes the Bugs item #1421290.
3187
return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
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><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);
3873
if(strlen($this->lispacer) > 0) {
3874
$this->x += $this->GetStringWidth($this->lispacer);
3884
$currentFontSize = $this->FontSize;
3885
$this->tempfontsize = $this->FontSizePt;
3886
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
3887
$this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
3891
$currentFontSize = $this->FontSize;
3892
$this->tempfontsize = $this->FontSizePt;
3893
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
3894
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
3898
$currentFontSize = $this->FontSize;
3899
$this->tempfontsize = $this->FontSizePt;
3900
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
3901
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)/3));
3905
if (isset($attr['color']) AND $attr['color']!='') {
3906
$coul = $this->convertColorHexToDec($attr['color']);
3907
$this->SetTextColor($coul['R'],$coul['G'],$coul['B']);
3908
$this->issetcolor=true;
3910
if (isset($attr['face']) and in_array(strtolower($attr['face']), $this->fontlist)) {
3911
$this->SetFont(strtolower($attr['FACE']));
3912
$this->issetfont=true;
3914
if (isset($attr['size'])) {
3915
$headsize = intval($attr['size']);
3919
$currentFontSize = $this->FontSize;
3920
$this->tempfontsize = $this->FontSizePt;
3921
$this->SetFontSize($this->FontSizePt + $headsize);
3922
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
3931
$headsize = (4 - substr($tag, 1)) * 2;
3932
$currentFontSize = $this->FontSize;
3933
$this->tempfontsize = $this->FontSizePt;
3934
$this->SetFontSize($this->FontSizePt + $headsize);
3935
$this->setStyle('b', true);
3936
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
3943
* Process closing tags.
3944
* @param string $tag tag name (in uppercase)
3947
function closedHTMLTagHandler($tag) {
3952
$this->tdbegin = false;
3954
$this->tdheight = 0;
3955
$this->tdalign = "L";
3956
$this->tdbgcolor = false;
3957
$this->SetFillColor($this->prevFillColor[0], $this->prevFillColor[1], $this->prevFillColor[2]);
3965
$this->tableborder=0;
3969
$this->setStyle('b', false);
3973
$this->setStyle('i', false);
3979
$this->setStyle($tag, false);
3987
$currentFontSize = $this->FontSize;
3988
$this->SetFontSize($this->tempfontsize);
3989
$this->tempfontsize = $this->FontSizePt;
3990
$this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
3994
$currentFontSize = $this->FontSize;
3995
$this->SetFontSize($this->tempfontsize);
3996
$this->tempfontsize = $this->FontSizePt;
3997
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
4001
$currentFontSize = $this->FontSize;
4002
$this->SetFontSize($this->tempfontsize);
4003
$this->tempfontsize = $this->FontSizePt;
4004
$this->SetXY($this->GetX(), $this->GetY() - (($this->FontSize - $currentFontSize)/3));
4008
if ($this->issetcolor == true) {
4009
$this->SetTextColor($this->prevTextColor[0], $this->prevTextColor[1], $this->prevTextColor[2]);
4011
if ($this->issetfont) {
4012
$this->FontFamily = $this->prevFontFamily;
4013
$this->FontStyle = $this->prevFontStyle;
4014
$this->SetFont($this->FontFamily);
4015
$this->issetfont = false;
4017
$currentFontSize = $this->FontSize;
4018
$this->SetFontSize($this->tempfontsize);
4019
$this->tempfontsize = $this->FontSizePt;
4020
//$this->TextColor = $this->prevTextColor;
4021
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
4033
$this->lispacer = "";
4042
$currentFontSize = $this->FontSize;
4043
$this->SetFontSize($this->tempfontsize);
4044
$this->tempfontsize = $this->FontSizePt;
4045
$this->setStyle('b', false);
4047
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
4058
* @param string $tag tag name (in lowercase)
4059
* @param boolean $enable
4062
function setStyle($tag, $enable) {
4063
//Modify style and select corresponding font
4064
$this->$tag += ($enable ? 1 : -1);
4066
foreach(array('b', 'i', 'u') as $s) {
4071
$this->SetFont('', $style);
4075
* Output anchor link.
4076
* @param string $url link URL
4077
* @param string $name link name
4078
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
4081
function addHtmlLink($url, $name, $fill=0) {
4083
$this->SetTextColor(0, 0, 255);
4084
$this->setStyle('u', true);
4085
$this->Write($this->lasth, $name, $url, $fill);
4086
$this->setStyle('u', false);
4087
$this->SetTextColor(0);
4091
* Returns an associative array (keys: R,G,B) from
4092
* a hex html code (e.g. #3FE5AA).
4093
* @param string $color hexadecimal html color [#rrggbb]
4097
function convertColorHexToDec($color = "#000000"){
4098
$tbl_color = array();
4099
$tbl_color['R'] = hexdec(substr($color, 1, 2));
4100
$tbl_color['G'] = hexdec(substr($color, 3, 2));
4101
$tbl_color['B'] = hexdec(substr($color, 5, 2));
4106
* Converts pixels to millimeters in 72 dpi.
4107
* @param int $px pixels
4108
* @return float millimeters
4111
function pixelsToMillimeters($px){
4112
return $px * 25.4 / 72;
4116
* Reverse function for htmlentities.
4117
* Convert entities in UTF-8.
4119
* @param $text_to_convert Text to convert.
4120
* @return string converted
4122
function unhtmlentities($text_to_convert) {
4123
require_once(dirname(__FILE__).'/html_entity_decode_php4.php');
4124
return html_entity_decode_php4($text_to_convert);
4128
//Handle special IE contype request
4129
if(isset($_SERVER['HTTP_USER_AGENT']) AND ($_SERVER['HTTP_USER_AGENT']=='contype')) {
4130
header('Content-Type: application/pdf');
4135
//============================================================+
4137
//============================================================+