Bonjour a tous, je tourne en rond depuis des mois pour la mise en page de ma PDF généré via PHP.

J'ai 3 principaux souci,
- 1 je n'arrive pas a mettre uniquement les bordures extérieures d'un tableau en visible et si possible mettre une couleur, si je mets 1 a la place de 0 ce sont toutes les bordures y compris interieurs qui s'affichent
- 2 je n'arrive pas a decaller les tableaux de X vers la droite, meme en utilisant $pdf->SetXY(30,0); avant le $pdf->WriteHTML($text_1);
- 3 Pourquoi quand je mets en gras une partie d'une phrase celle-ci se barre completement a droite au lieu de rester juste derriere le dernier mot en normal ?

Merci milles fois pour toute votre aide


Mon code $texte_1 ="<table><tr><td width="250" height="30" align="CENTER">Je m'appelle <b>toto</b></td></tr></table>";

Mon appel de fonction :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
require('fpdf.php');
require('fpdfHTML.php');
 
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->SetFont('times','',11);
$pdf->AddPage();
//$pdf->SetXY(30,0);
$pdf->WriteHTML($text_1);
 
$pdf->Output('test.pdf', $_GET['download'] ? 'D':'I');
$pdf->Output('test.pdf', 'F');


mon programme fpdfHTML :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
<?php
//require('fpdf.php');
 
//function hex2dec
//returns an associative array (keys: R,G,B) from a hex html code (e.g. #3FE5AA)
function hex2dec($couleur = "#000000"){
	$R = substr($couleur, 1, 2);
	$rouge = hexdec($R);
	$V = substr($couleur, 3, 2);
	$vert = hexdec($V);
	$B = substr($couleur, 5, 2);
	$bleu = hexdec($B);
	$tbl_couleur = array();
	$tbl_couleur['R']=$rouge;
	$tbl_couleur['G']=$vert;
	$tbl_couleur['B']=$bleu;
	return $tbl_couleur;
}
 
//conversion pixel -> millimeter in 72 dpi
function px2mm($px){
	return $px*25.4/72;
}
 
function txtentities($html){
	$trans = get_html_translation_table(HTML_ENTITIES);
	$trans = array_flip($trans);
	return strtr($html, $trans);
}
////////////////////////////////////
 
class PDF extends FPDF
{
//variables of html parser
protected $B;
protected $I;
protected $U;
protected $HREF;
protected $fontList;
protected $issetfont;
protected $issetcolor;
protected $ALIGN='';
 
function __construct($orientation='P', $unit='mm', $format='A4')
{
	//Call parent constructor
	parent::__construct($orientation,$unit,$format);
 
	//Initialization
	$this->B=0;
	$this->I=0;
	$this->U=0;
	$this->HREF='';
 
	$this->tableborder=0;
	$this->tdbegin=false;
	$this->tdwidth=0;
	$this->tdheight=0;
	$this->tdalign="L";
	$this->tdbgcolor=false;
 
	$this->oldx=0;
	$this->oldy=0;
 
	$this->fontlist=array("arial","times","courier","helvetica","symbol");
	$this->issetfont=false;
	$this->issetcolor=false;
}
 
//////////////////////////////////////
//html parser
 
function WriteHTML($html)
{
	$html=strip_tags($html,"<b><u><i><a><img><p><br><strong><em><font><tr><blockquote><hr><td><tr><table><sup><span>"); //remove all unsupported tags
	$html=str_replace("\n",'',$html); //replace carriage returns with spaces
	$html=str_replace("\t",'',$html); //replace carriage returns with spaces
	$a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE); //explode the string
	foreach($a as $i=>$e)
	{
		if($i%2==0)
		{
			//Text
			if($this->HREF)
				$this->PutLink($this->HREF,$e);
            elseif($this->ALIGN=='center')
                $this->Cell(0,0,$e,0,1,'C');
			elseif($this->tdbegin) {
				if(trim($e)!='' && $e!="&nbsp;") {
					$this->Cell($this->tdwidth,$this->tdheight,$e,$this->tableborder,'',$this->tdalign,$this->tdbgcolor);
				}
				elseif($e=="&nbsp;") {
					$this->Cell($this->tdwidth,$this->tdheight,'',$this->tableborder,'',$this->tdalign,$this->tdbgcolor);
				}
			}
			else
				$this->Write(5,stripslashes(txtentities($e)));
		}
		else
		{
			//Tag
			if($e[0]=='/')
				$this->CloseTag(strtoupper(substr($e,1)));
			else
			{
				//Extract attributes
				$a2=explode(' ',$e);
				$tag=strtoupper(array_shift($a2));
				$attr=array();
				foreach($a2 as $v)
				{
					if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
						$attr[strtoupper($a3[1])]=$a3[2];
				}
				$this->OpenTag($tag,$attr);
			}
		}
	}
}
 
function OpenTag($tag, $attr)
{
	//Opening tag
	switch($tag){
 
		case 'SUP':
			if( !empty($attr['SUP']) ) {	
				//Set current font to 6pt 	
				$this->SetFont('','',6);
				//Start 125cm plus width of cell to the right of left margin 		
				//Superscript "1" 
				$this->Cell(2,2,$attr['SUP'],0,0,'L');
			}
			break;
 
		case 'TABLE': // TABLE-BEGIN
			if( !empty($attr['BORDER']) ) $this->tableborder=$attr['BORDER'];
			else $this->tableborder=0;
			break;
		case 'TR': //TR-BEGIN
			break;
		case 'TD': // TD-BEGIN
			if( !empty($attr['WIDTH']) ) $this->tdwidth=($attr['WIDTH']/4);
			else $this->tdwidth=40; // Set to your own width if you need bigger fixed cells
			if( !empty($attr['HEIGHT']) ) $this->tdheight=($attr['HEIGHT']/6);
			else $this->tdheight=6; // Set to your own height if you need bigger fixed cells
			if( !empty($attr['ALIGN']) ) {
				$align=$attr['ALIGN'];		
				if($align=='LEFT') $this->tdalign='L';
				if($align=='CENTER') $this->tdalign='C';
				if($align=='RIGHT') $this->tdalign='R';
			}
			else $this->tdalign='L'; // Set to your own
			if( !empty($attr['BGCOLOR']) ) {
				$coul=hex2dec($attr['BGCOLOR']);
					$this->SetFillColor($coul['R'],$coul['G'],$coul['B']);
					$this->tdbgcolor=true;
				}
			$this->tdbegin=true;
			break;
 
		case 'HR':
			if( !empty($attr['WIDTH']) )
				$Width = $attr['WIDTH'];
			else
				$Width = $this->w - $this->lMargin-$this->rMargin;
			$x = $this->GetX();
			$y = $this->GetY();
			$this->SetLineWidth(0.2);
			$this->Line($x,$y,$x+$Width,$y);
			$this->SetLineWidth(0.2);
			$this->Ln(1);
			break;
		case 'STRONG':
			$this->SetStyle('B',true);
			break;
		case 'EM':
			$this->SetStyle('I',true);
			break;
		case 'B':
		case 'I':
		case 'U':
			$this->SetStyle($tag,true);
			break;
		case 'A':
			$this->HREF=$attr['HREF'];
			break;
		case 'IMG':
			if(isset($attr['SRC']) && (isset($attr['WIDTH']) || isset($attr['HEIGHT']))) {
				if(!isset($attr['WIDTH']))
					$attr['WIDTH'] = 0;
				if(!isset($attr['HEIGHT']))
					$attr['HEIGHT'] = 0;
				$this->Image($attr['SRC'], $this->GetX(), $this->GetY(), px2mm($attr['WIDTH']), px2mm($attr['HEIGHT']));
			}
			break;
		case 'BLOCKQUOTE':
		case 'BR':
			$this->Ln(5);
			break;
		case 'P':
   	        $this->ALIGN=$attr['ALIGN'];
			break;
		case 'FONT':
			if (isset($attr['COLOR']) && $attr['COLOR']!='') {
				$coul=hex2dec($attr['COLOR']);
				$this->SetTextColor($coul['R'],$coul['G'],$coul['B']);
				$this->issetcolor=true;
			}
			if (isset($attr['FACE']) && in_array(strtolower($attr['FACE']), $this->fontlist)) {
				$this->SetFont(strtolower($attr['FACE']));
				$this->issetfont=true;
			}
			if (isset($attr['FACE']) && in_array(strtolower($attr['FACE']), $this->fontlist) && isset($attr['SIZE']) && $attr['SIZE']!='') {
				$this->SetFont(strtolower($attr['FACE']),'',$attr['SIZE']);
				$this->issetfont=true;
			}
			break;
	}
}
 
function CloseTag($tag)
{
	//Closing tag
	if($tag=='SUP') {
	}
 
	if($tag=='TD') { // TD-END
		$this->tdbegin=false;
		$this->tdwidth=0;
		$this->tdheight=0;
		$this->tdalign="L";
		$this->tdbgcolor=false;
	}
	if($tag=='TR') { // TR-END
		$this->Ln();
	}
	if($tag=='TABLE') { // TABLE-END
		$this->tableborder=0;
	}
 
	if($tag=='STRONG')
		$tag='B';
	if($tag=='EM')
		$tag='I';
	if($tag=='B' || $tag=='I' || $tag=='U')
		$this->SetStyle($tag,false);
	if($tag=='A')
		$this->HREF='';
    if($tag=='SPAN')
        $this->ALIGN='';
	if($tag=='FONT'){
		if ($this->issetcolor==true) {
			$this->SetTextColor(0);
		}
		if ($this->issetfont) {
			$this->SetFont('arial');
			$this->issetfont=false;
		}
	}
}
 
function SetStyle($tag, $enable)
{
	//Modify style and select corresponding font
	$this->$tag+=($enable ? 1 : -1);
	$style='';
	foreach(array('B','I','U') as $s) {
		if($this->$s>0)
			$style.=$s;
	}
	$this->SetFont('',$style);
}
 
function PutLink($URL, $txt)
{
	//Put a hyperlink
	$this->SetTextColor(0,0,255);
	$this->SetStyle('U',true);
	$this->Write(5,$txt,$URL);
	$this->SetStyle('U',false);
	$this->SetTextColor(0);
}
 
function Footer()
{
    // Positionnement à 1,5 cm du bas
    $this->SetFont('Arial','I',7);
    $this->SetY(-24);
    $this->Cell(0,10,'MBC FINANCES (SAS) , siege social 76 Allee Louis Bleriot 30320 MARGUERITTES, inscrite au RCS de Nimes sous le n 830087698 ainsi qu a l Orias sous le n 17004452',0,0,'L');
    $this->SetY(-21);
    $this->Cell(0,10,'en tant que Courtier en Operation de Banque et Mandataire d Intermediaire en Assurance. Vous pouvez vous opposer sans frais a ce que vos donnees personnelles',0,0,'L');
    $this->SetY(-18);
    $this->Cell(0,10,'soient utilisees a des fins de sollicitations commerciales en ecrivant a : MBC FINANCES - Service reclamation - 76 Allee Louis Bleriot 30320 Marguerittes. ',0,0,'L');
    $this->SetY(-15);
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
	$this->Image("images/bordure-bleu-h.jpg",5,290,200,0);
}
 
function Header()
{
   $this->Image("images/bordure-bleu-h.jpg",5,5,200,0);
   $this->Image("images/bordure-bleu-v.jpg",5,5,0,285);
   $this->Image("images/bordure-bleu-v.jpg",205,5,0,285);
}
 
 
function HTML2RGB($c, &$r, &$g, &$b)
{
    static $colors = array('aliceblue'=>'#F0F8FF', 'antiquewhite'=>'#FAEBD7', 'aqua'=>'#00FFFF', 'aquamarine'=>'#7FFFD4', 'azure'=>'#F0FFFF',
        'beige'=>'#F5F5DC', 'bisque'=>'#FFE4C4', 'black'=>'#000000', 'blanchedalmond'=>'#FFEBCD', 'blue'=>'#0000FF', 'blueviolet'=>'#8A2BE2',
        'brown'=>'#A52A2A', 'burlywood'=>'#DEB887', 'cadetblue'=>'#5F9EA0', 'chartreuse'=>'#7FFF00', 'chocolate'=>'#D2691E', 'coral'=>'#FF7F50',
        'cornflowerblue'=>'#6495ED', 'cornsilk'=>'#FFF8DC', 'crimson'=>'#DC143C', 'cyan'=>'#00FFFF', 'darkblue'=>'#00008B', 'darkcyan'=>'#008B8B',
        'darkgoldenrod'=>'#B8860B', 'darkgray'=>'#A9A9A9', 'darkgreen'=>'#006400', 'darkkhaki'=>'#BDB76B', 'darkmagenta'=>'#8B008B',
        'darkolivegreen'=>'#556B2F', 'darkorange'=>'#FF8C00', 'darkorchid'=>'#9932CC', 'darkred'=>'#8B0000', 'darksalmon'=>'#E9967A',
        'darkseagreen'=>'#8DBC8F', 'darkslateblue'=>'#483D8B', 'darkslategray'=>'#2F4F4F', 'darkturquoise'=>'#00DED1', 'darkviolet'=>'#9400D3',
        'deeppink'=>'#FF1493', 'deepskyblue'=>'#00BFFF', 'dimgray'=>'#696969', 'dodgerblue'=>'#1E90FF', 'firebrick'=>'#B22222',
        'floralwhite'=>'#FFFAF0', 'forestgreen'=>'#228B22', 'fuchsia'=>'#FF00FF', 'gainsboro'=>'#DCDCDC', 'ghostwhite'=>'#F8F8FF',
        'gold'=>'#FFD700', 'goldenrod'=>'#DAA520', 'gray'=>'#808080', 'green'=>'#008000', 'greenyellow'=>'#ADFF2F', 'honeydew'=>'#F0FFF0',
        'hotpink'=>'#FF69B4', 'indianred'=>'#CD5C5C', 'indigo'=>'#4B0082', 'ivory'=>'#FFFFF0', 'khaki'=>'#F0E68C', 'lavender'=>'#E6E6FA',
        'lavenderblush'=>'#FFF0F5', 'lawngreen'=>'#7CFC00', 'lemonchiffon'=>'#FFFACD', 'lightblue'=>'#ADD8E6', 'lightcoral'=>'#F08080',
        'lightcyan'=>'#E0FFFF', 'lightgoldenrodyellow'=>'#FAFAD2', 'lightgreen'=>'#90EE90', 'lightgrey'=>'#D3D3D3', 'lightpink'=>'#FFB6C1',
        'lightsalmon'=>'#FFA07A', 'lightseagreen'=>'#20B2AA', 'lightskyblue'=>'#87CEFA', 'lightslategray'=>'#778899', 'lightsteelblue'=>'#B0C4DE',
        'lightyellow'=>'#FFFFE0', 'lime'=>'#00FF00', 'limegreen'=>'#32CD32', 'linen'=>'#FAF0E6', 'magenta'=>'#FF00FF', 'maroon'=>'#800000',
        'mediumaquamarine'=>'#66CDAA', 'mediumblue'=>'#0000CD', 'mediumorchid'=>'#BA55D3', 'mediumpurple'=>'#9370DB', 'mediumseagreen'=>'#3CB371',
        'mediumslateblue'=>'#7B68EE', 'mediumspringgreen'=>'#00FA9A', 'mediumturquoise'=>'#48D1CC', 'mediumvioletred'=>'#C71585',
        'midnightblue'=>'#191970', 'mintcream'=>'#F5FFFA', 'mistyrose'=>'#FFE4E1', 'moccasin'=>'#FFE4B5', 'navajowhite'=>'#FFDEAD',
        'navy'=>'#000080', 'oldlace'=>'#FDF5E6', 'olive'=>'#808000', 'orange'=>'#FFA500', 'orangered'=>'#FF4500', 'orchid'=>'#DA70D6',
        'palegoldenrod'=>'#EEE8AA', 'palegreen'=>'#98FB98', 'paleturquoise'=>'#AFEEEE', 'palevioletred'=>'#DB7093', 'papayawhip'=>'#FFEFD5',
        'peachpuff'=>'#FFDAB9', 'peru'=>'#CD853F', 'pink'=>'#FFC8CB', 'plum'=>'#DDA0DD', 'powderblue'=>'#B0E0E6', 'purple'=>'#800080',
        'red'=>'#FF0000', 'rosybrown'=>'#BC8F8F', 'royalblue'=>'#4169E1', 'saddlebrown'=>'#8B4513', 'salmon'=>'#FA8072', 'sandybrown'=>'#F4A460',
        'seagreen'=>'#2E8B57', 'seashell'=>'#FFF5EE', 'sienna'=>'#A0522D', 'silver'=>'#C0C0C0', 'skyblue'=>'#87CEEB', 'slateblue'=>'#6A5ACD',
        'snow'=>'#FFFAFA', 'springgreen'=>'#00FF7F', 'steelblue'=>'#4682B4', 'tan'=>'#D2B48C', 'teal'=>'#008080', 'thistle'=>'#D8BFD8',
        'tomato'=>'#FF6347', 'turquoise'=>'#40E0D0', 'violet'=>'#EE82EE', 'wheat'=>'#F5DEB3', 'white'=>'#FFFFFF', 'whitesmoke'=>'#F5F5F5',
        'yellow'=>'#FFFF00', 'yellowgreen'=>'#9ACD32');
 
    $c = strtolower($c);
    if(isset($colors[$c]))
        $c = $colors[$c];
    if($c[0]!='#')
        $this->Error('Incorrect color: '.$c);
    $r = hexdec(substr($c,1,2));
    $g = hexdec(substr($c,3,2));
    $b = hexdec(substr($c,5,2));
}
 
function SetDrawColor($r, $g=-1, $b=-1)
{
    if(is_string($r))
        $this->HTML2RGB($r,$r,$g,$b);
    parent::SetDrawColor($r,$g,$b);
}
 
function SetFillColor($r, $g=-1, $b=-1)
{
    if(is_string($r))
        $this->HTML2RGB($r,$r,$g,$b);
    parent::SetFillColor($r,$g,$b);
}
 
function SetTextColor($r, $g=-1, $b=-1)
{
    if(is_string($r))
        $this->HTML2RGB($r,$r,$g,$b);
    parent::SetTextColor($r,$g,$b);
}
 
function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $indent=0)
{
    //Output text with automatic or explicit line breaks
    $cw=&$this->CurrentFont['cw'];
    if($w==0)
        $w=$this->w-$this->rMargin-$this->x;
 
    $wFirst = $w-$indent;
    $wOther = $w;
 
    $wmaxFirst=($wFirst-2*$this->cMargin)*1000/$this->FontSize;
    $wmaxOther=($wOther-2*$this->cMargin)*1000/$this->FontSize;
 
    $s=str_replace("\r",'',$txt);
    $nb=strlen($s);
    if($nb>0 && $s[$nb-1]=="\n")
        $nb--;
    $b=0;
    if($border)
    {
        if($border==1)
        {
            $border='LTRB';
            $b='LRT';
            $b2='LR';
        }
        else
        {
            $b2='';
            if(is_int(strpos($border,'L')))
                $b2.='L';
            if(is_int(strpos($border,'R')))
                $b2.='R';
            $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
        }
    }
    $sep=-1;
    $i=0;
    $j=0;
    $l=0;
    $ns=0;
    $nl=1;
        $first=true;
    while($i<$nb)
    {
        //Get next character
        $c=$s[$i];
        if($c=="\n")
        {
            //Explicit line break
            if($this->ws>0)
            {
                $this->ws=0;
                $this->_out('0 Tw');
            }
            $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
            $i++;
            $sep=-1;
            $j=$i;
            $l=0;
            $ns=0;
            $nl++;
            if($border && $nl==2)
                $b=$b2;
            continue;
        }
        if($c==' ')
        {
            $sep=$i;
            $ls=$l;
            $ns++;
        }
        $l+=$cw[$c];
 
        if ($first)
        {
            $wmax = $wmaxFirst;
            $w = $wFirst;
        }
        else
        {
            $wmax = $wmaxOther;
            $w = $wOther;
        }
 
        if($l>$wmax)
        {
            //Automatic line break
            if($sep==-1)
            {
                if($i==$j)
                    $i++;
                if($this->ws>0)
                {
                    $this->ws=0;
                    $this->_out('0 Tw');
                }
                $SaveX = $this->x; 
                if ($first && $indent>0)
                {
                    $this->SetX($this->x + $indent);
                    $first=false;
                }
                $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
                    $this->SetX($SaveX);
            }
            else
            {
                if($align=='J')
                {
                    $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
                    $this->_out(sprintf('%.3f Tw',$this->ws*$this->k));
                }
                $SaveX = $this->x; 
                if ($first && $indent>0)
                {
                    $this->SetX($this->x + $indent);
                    $first=false;
                }
                $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
                    $this->SetX($SaveX);
                $i=$sep+1;
            }
            $sep=-1;
            $j=$i;
            $l=0;
            $ns=0;
            $nl++;
            if($border && $nl==2)
                $b=$b2;
        }
        else
            $i++;
    }
    //Last chunk
    if($this->ws>0)
    {
        $this->ws=0;
        $this->_out('0 Tw');
    }
    if($border && is_int(strpos($border,'B')))
        $b.='B';
    $this->Cell($w,$h,substr($s,$j,$i),$b,2,$align,$fill);
    $this->x=$this->lMargin;
    }
 
function drawTextBox($strText, $w, $h, $align='L', $valign='T', $border=false)
{
    $xi=$this->GetX();
    $yi=$this->GetY();
 
    $hrow=$this->FontSize;
    $textrows=$this->drawRows($w,$hrow,$strText,0,$align,0,0,0);
    $maxrows=floor($h/$this->FontSize);
    $rows=min($textrows,$maxrows);
 
    $dy=0;
    if (strtoupper($valign)=='M')
        $dy=($h-$rows*$this->FontSize)/2;
    if (strtoupper($valign)=='B')
        $dy=$h-$rows*$this->FontSize;
 
    $this->SetY($yi+$dy);
    $this->SetX($xi);
 
    $this->drawRows($w,$hrow,$strText,0,$align,false,$rows,1);
 
    if ($border)
        $this->Rect($xi,$yi,$w,$h);
}
 
function drawRows($w, $h, $txt, $border=0, $align='J', $fill=false, $maxline=0, $prn=0)
{
    $cw=&$this->CurrentFont['cw'];
    if($w==0)
        $w=$this->w-$this->rMargin-$this->x;
    $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
    $s=str_replace("\r",'',$txt);
    $nb=strlen($s);
    if($nb>0 && $s[$nb-1]=="\n")
        $nb--;
    $b=0;
    if($border)
    {
        if($border==1)
        {
            $border='LTRB';
            $b='LRT';
            $b2='LR';
        }
        else
        {
            $b2='';
            if(is_int(strpos($border,'L')))
                $b2.='L';
            if(is_int(strpos($border,'R')))
                $b2.='R';
            $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
        }
    }
    $sep=-1;
    $i=0;
    $j=0;
    $l=0;
    $ns=0;
    $nl=1;
    while($i<$nb)
    {
        //Get next character
        $c=$s[$i];
        if($c=="\n")
        {
            //Explicit line break
            if($this->ws>0)
            {
                $this->ws=0;
                if ($prn==1) $this->_out('0 Tw');
            }
            if ($prn==1) {
                $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
            }
            $i++;
            $sep=-1;
            $j=$i;
            $l=0;
            $ns=0;
            $nl++;
            if($border && $nl==2)
                $b=$b2;
            if ( $maxline && $nl > $maxline )
                return substr($s,$i);
            continue;
        }
        if($c==' ')
        {
            $sep=$i;
            $ls=$l;
            $ns++;
        }
        $l+=$cw[$c];
        if($l>$wmax)
        {
            //Automatic line break
            if($sep==-1)
            {
                if($i==$j)
                    $i++;
                if($this->ws>0)
                {
                    $this->ws=0;
                    if ($prn==1) $this->_out('0 Tw');
                }
                if ($prn==1) {
                    $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
                }
            }
            else
            {
                if($align=='J')
                {
                    $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
                    if ($prn==1) $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
                }
                if ($prn==1){
                    $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
                }
                $i=$sep+1;
            }
            $sep=-1;
            $j=$i;
            $l=0;
            $ns=0;
            $nl++;
            if($border && $nl==2)
                $b=$b2;
            if ( $maxline && $nl > $maxline )
                return substr($s,$i);
        }
        else
            $i++;
    }
    //Last chunk
    if($this->ws>0)
    {
        $this->ws=0;
        if ($prn==1) $this->_out('0 Tw');
    }
    if($border && is_int(strpos($border,'B')))
        $b.='B';
    if ($prn==1) {
        $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
    }
    $this->x=$this->lMargin;
    return $nl;
}
}
 
?>