-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpdf.php
1910 lines (1814 loc) · 49.1 KB
/
fpdf.php
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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*******************************************************************************
* FPDF *
* *
* Version: 1.83 *
* Date: 2021-04-18 *
* Author: Olivier PLATHEY *
*******************************************************************************/
define('FPDF_VERSION','1.83');
class FPDF
{
protected $page; // current page number
protected $n; // current object number
protected $offsets; // array of object offsets
protected $buffer; // buffer holding in-memory PDF
protected $pages; // array containing pages
protected $state; // current document state
protected $compress; // compression flag
protected $k; // scale factor (number of points in user unit)
protected $DefOrientation; // default orientation
protected $CurOrientation; // current orientation
protected $StdPageSizes; // standard page sizes
protected $DefPageSize; // default page size
protected $CurPageSize; // current page size
protected $CurRotation; // current page rotation
protected $PageInfo; // page-related data
protected $wPt, $hPt; // dimensions of current page in points
protected $w, $h; // dimensions of current page in user unit
protected $lMargin; // left margin
protected $tMargin; // top margin
protected $rMargin; // right margin
protected $bMargin; // page break margin
protected $cMargin; // cell margin
protected $x, $y; // current position in user unit
protected $lasth; // height of last printed cell
protected $LineWidth; // line width in user unit
protected $fontpath; // path containing fonts
protected $CoreFonts; // array of core font names
protected $fonts; // array of used fonts
protected $FontFiles; // array of font files
protected $encodings; // array of encodings
protected $cmaps; // array of ToUnicode CMaps
protected $FontFamily; // current font family
protected $FontStyle; // current font style
protected $underline; // underlining flag
protected $CurrentFont; // current font info
protected $FontSizePt; // current font size in points
protected $FontSize; // current font size in user unit
protected $DrawColor; // commands for drawing color
protected $FillColor; // commands for filling color
protected $TextColor; // commands for text color
protected $ColorFlag; // indicates whether fill and text colors are different
protected $WithAlpha; // indicates whether alpha channel is used
protected $ws; // word spacing
protected $images; // array of used images
protected $PageLinks; // array of links in pages
protected $links; // array of internal links
protected $AutoPageBreak; // automatic page breaking
protected $PageBreakTrigger; // threshold used to trigger page breaks
protected $InHeader; // flag set when processing header
protected $InFooter; // flag set when processing footer
protected $AliasNbPages; // alias for total number of pages
protected $ZoomMode; // zoom display mode
protected $LayoutMode; // layout display mode
protected $metadata; // document properties
protected $PDFVersion; // PDF version number
/*******************************************************************************
* Public methods *
*******************************************************************************/
function __construct($orientation='P', $unit='mm', $size='A4')
{
// Some checks
$this->_dochecks();
// Initialization of properties
$this->state = 0;
$this->page = 0;
$this->n = 2;
$this->buffer = '';
$this->pages = array();
$this->PageInfo = array();
$this->fonts = array();
$this->FontFiles = array();
$this->encodings = array();
$this->cmaps = array();
$this->images = array();
$this->links = array();
$this->InHeader = false;
$this->InFooter = false;
$this->lasth = 0;
$this->FontFamily = '';
$this->FontStyle = '';
$this->FontSizePt = 12;
$this->underline = false;
$this->DrawColor = '0 G';
$this->FillColor = '0 g';
$this->TextColor = '0 g';
$this->ColorFlag = false;
$this->WithAlpha = false;
$this->ws = 0;
// Font path
if(defined('FPDF_FONTPATH'))
{
$this->fontpath = FPDF_FONTPATH;
if(substr($this->fontpath,-1)!='/' && substr($this->fontpath,-1)!='\\')
$this->fontpath .= '/';
}
elseif(is_dir(dirname(__FILE__).'/font'))
$this->fontpath = dirname(__FILE__).'/font/';
else
$this->fontpath = 'C:\xampp\htdocs\yok-lulus-mbd-main\font';
// Core fonts
$this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats');
// Scale factor
if($unit=='pt')
$this->k = 1;
elseif($unit=='mm')
$this->k = 72/25.4;
elseif($unit=='cm')
$this->k = 72/2.54;
elseif($unit=='in')
$this->k = 72;
else
$this->Error('Incorrect unit: '.$unit);
// Page sizes
$this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28),
'letter'=>array(612,792), 'legal'=>array(612,1008));
$size = $this->_getpagesize($size);
$this->DefPageSize = $size;
$this->CurPageSize = $size;
// Page orientation
$orientation = strtolower($orientation);
if($orientation=='p' || $orientation=='portrait')
{
$this->DefOrientation = 'P';
$this->w = $size[0];
$this->h = $size[1];
}
elseif($orientation=='l' || $orientation=='landscape')
{
$this->DefOrientation = 'L';
$this->w = $size[1];
$this->h = $size[0];
}
else
$this->Error('Incorrect orientation: '.$orientation);
$this->CurOrientation = $this->DefOrientation;
$this->wPt = $this->w*$this->k;
$this->hPt = $this->h*$this->k;
// Page rotation
$this->CurRotation = 0;
// Page margins (1 cm)
$margin = 28.35/$this->k;
$this->SetMargins($margin,$margin);
// Interior cell margin (1 mm)
$this->cMargin = $margin/10;
// Line width (0.2 mm)
$this->LineWidth = .567/$this->k;
// Automatic page break
$this->SetAutoPageBreak(true,2*$margin);
// Default display mode
$this->SetDisplayMode('default');
// Enable compression
$this->SetCompression(true);
// Set default PDF version number
$this->PDFVersion = '1.3';
}
function SetMargins($left, $top, $right=null)
{
// Set left, top and right margins
$this->lMargin = $left;
$this->tMargin = $top;
if($right===null)
$right = $left;
$this->rMargin = $right;
}
function SetLeftMargin($margin)
{
// Set left margin
$this->lMargin = $margin;
if($this->page>0 && $this->x<$margin)
$this->x = $margin;
}
function SetTopMargin($margin)
{
// Set top margin
$this->tMargin = $margin;
}
function SetRightMargin($margin)
{
// Set right margin
$this->rMargin = $margin;
}
function SetAutoPageBreak($auto, $margin=0)
{
// Set auto page break mode and triggering margin
$this->AutoPageBreak = $auto;
$this->bMargin = $margin;
$this->PageBreakTrigger = $this->h-$margin;
}
function SetDisplayMode($zoom, $layout='default')
{
// Set display mode in viewer
if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom))
$this->ZoomMode = $zoom;
else
$this->Error('Incorrect zoom display mode: '.$zoom);
if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default')
$this->LayoutMode = $layout;
else
$this->Error('Incorrect layout display mode: '.$layout);
}
function SetCompression($compress)
{
// Set page compression
if(function_exists('gzcompress'))
$this->compress = $compress;
else
$this->compress = false;
}
function SetTitle($title, $isUTF8=false)
{
// Title of document
$this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title);
}
function SetAuthor($author, $isUTF8=false)
{
// Author of document
$this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author);
}
function SetSubject($subject, $isUTF8=false)
{
// Subject of document
$this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject);
}
function SetKeywords($keywords, $isUTF8=false)
{
// Keywords of document
$this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords);
}
function SetCreator($creator, $isUTF8=false)
{
// Creator of document
$this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator);
}
function AliasNbPages($alias='{nb}')
{
// Define an alias for total number of pages
$this->AliasNbPages = $alias;
}
function Error($msg)
{
// Fatal error
throw new Exception('FPDF error: '.$msg);
}
function Close()
{
// Terminate document
if($this->state==3)
return;
if($this->page==0)
$this->AddPage();
// Page footer
$this->InFooter = true;
$this->Footer();
$this->InFooter = false;
// Close page
$this->_endpage();
// Close document
$this->_enddoc();
}
function AddPage($orientation='', $size='', $rotation=0)
{
// Start a new page
if($this->state==3)
$this->Error('The document is closed');
$family = $this->FontFamily;
$style = $this->FontStyle.($this->underline ? 'U' : '');
$fontsize = $this->FontSizePt;
$lw = $this->LineWidth;
$dc = $this->DrawColor;
$fc = $this->FillColor;
$tc = $this->TextColor;
$cf = $this->ColorFlag;
if($this->page>0)
{
// Page footer
$this->InFooter = true;
$this->Footer();
$this->InFooter = false;
// Close page
$this->_endpage();
}
// Start new page
$this->_beginpage($orientation,$size,$rotation);
// Set line cap style to square
$this->_out('2 J');
// Set line width
$this->LineWidth = $lw;
$this->_out(sprintf('%.2F w',$lw*$this->k));
// Set font
if($family)
$this->SetFont($family,$style,$fontsize);
// Set colors
$this->DrawColor = $dc;
if($dc!='0 G')
$this->_out($dc);
$this->FillColor = $fc;
if($fc!='0 g')
$this->_out($fc);
$this->TextColor = $tc;
$this->ColorFlag = $cf;
// Page header
$this->InHeader = true;
$this->Header();
$this->InHeader = false;
// Restore line width
if($this->LineWidth!=$lw)
{
$this->LineWidth = $lw;
$this->_out(sprintf('%.2F w',$lw*$this->k));
}
// Restore font
if($family)
$this->SetFont($family,$style,$fontsize);
// Restore colors
if($this->DrawColor!=$dc)
{
$this->DrawColor = $dc;
$this->_out($dc);
}
if($this->FillColor!=$fc)
{
$this->FillColor = $fc;
$this->_out($fc);
}
$this->TextColor = $tc;
$this->ColorFlag = $cf;
}
function Header()
{
// To be implemented in your own inherited class
}
function Footer()
{
// To be implemented in your own inherited class
}
function PageNo()
{
// Get current page number
return $this->page;
}
function SetDrawColor($r, $g=null, $b=null)
{
// Set color for all stroking operations
if(($r==0 && $g==0 && $b==0) || $g===null)
$this->DrawColor = sprintf('%.3F G',$r/255);
else
$this->DrawColor = sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255);
if($this->page>0)
$this->_out($this->DrawColor);
}
function SetFillColor($r, $g=null, $b=null)
{
// Set color for all filling operations
if(($r==0 && $g==0 && $b==0) || $g===null)
$this->FillColor = sprintf('%.3F g',$r/255);
else
$this->FillColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255);
$this->ColorFlag = ($this->FillColor!=$this->TextColor);
if($this->page>0)
$this->_out($this->FillColor);
}
function SetTextColor($r, $g=null, $b=null)
{
// Set color for text
if(($r==0 && $g==0 && $b==0) || $g===null)
$this->TextColor = sprintf('%.3F g',$r/255);
else
$this->TextColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255);
$this->ColorFlag = ($this->FillColor!=$this->TextColor);
}
function GetStringWidth($s)
{
// Get width of a string in the current font
$s = (string)$s;
$cw = &$this->CurrentFont['cw'];
$w = 0;
$l = strlen($s);
for($i=0;$i<$l;$i++)
$w += $cw[$s[$i]];
return $w*$this->FontSize/1000;
}
function SetLineWidth($width)
{
// Set line width
$this->LineWidth = $width;
if($this->page>0)
$this->_out(sprintf('%.2F w',$width*$this->k));
}
function Line($x1, $y1, $x2, $y2)
{
// Draw a line
$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));
}
function Rect($x, $y, $w, $h, $style='')
{
// Draw a rectangle
if($style=='F')
$op = 'f';
elseif($style=='FD' || $style=='DF')
$op = 'B';
else
$op = 'S';
$this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
}
function AddFont($family, $style='', $file='')
{
// Add a TrueType, OpenType or Type1 font
$family = strtolower($family);
if($file=='')
$file = str_replace(' ','',$family).strtolower($style).'.php';
$style = strtoupper($style);
if($style=='IB')
$style = 'BI';
$fontkey = $family.$style;
if(isset($this->fonts[$fontkey]))
return;
$info = $this->_loadfont($file);
$info['i'] = count($this->fonts)+1;
if(!empty($info['file']))
{
// Embedded font
if($info['type']=='TrueType')
$this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
else
$this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
}
$this->fonts[$fontkey] = $info;
}
function SetFont($family, $style='', $size=0)
{
// Select a font; size given in points
if($family=='')
$family = $this->FontFamily;
else
$family = strtolower($family);
$style = strtoupper($style);
if(strpos($style,'U')!==false)
{
$this->underline = true;
$style = str_replace('U','',$style);
}
else
$this->underline = false;
if($style=='IB')
$style = 'BI';
if($size==0)
$size = $this->FontSizePt;
// Test if font is already selected
if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size)
return;
// Test if font is already loaded
$fontkey = $family.$style;
if(!isset($this->fonts[$fontkey]))
{
// Test if one of the core fonts
if($family=='arial')
$family = 'helvetica';
if(in_array($family,$this->CoreFonts))
{
if($family=='symbol' || $family=='zapfdingbats')
$style = '';
$fontkey = $family.$style;
if(!isset($this->fonts[$fontkey]))
$this->AddFont($family,$style);
}
else
$this->Error('Undefined font: '.$family.' '.$style);
}
// Select it
$this->FontFamily = $family;
$this->FontStyle = $style;
$this->FontSizePt = $size;
$this->FontSize = $size/$this->k;
$this->CurrentFont = &$this->fonts[$fontkey];
if($this->page>0)
$this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}
function SetFontSize($size)
{
// Set font size in points
if($this->FontSizePt==$size)
return;
$this->FontSizePt = $size;
$this->FontSize = $size/$this->k;
if($this->page>0)
$this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}
function AddLink()
{
// Create a new internal link
$n = count($this->links)+1;
$this->links[$n] = array(0, 0);
return $n;
}
function SetLink($link, $y=0, $page=-1)
{
// Set destination of internal link
if($y==-1)
$y = $this->y;
if($page==-1)
$page = $this->page;
$this->links[$link] = array($page, $y);
}
function Link($x, $y, $w, $h, $link)
{
// Put a link on the page
$this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link);
}
function Text($x, $y, $txt)
{
// Output a string
if(!isset($this->CurrentFont))
$this->Error('No font has been set');
$s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
if($this->underline && $txt!='')
$s .= ' '.$this->_dounderline($x,$y,$txt);
if($this->ColorFlag)
$s = 'q '.$this->TextColor.' '.$s.' Q';
$this->_out($s);
}
function AcceptPageBreak()
{
// Accept automatic page break or not
return $this->AutoPageBreak;
}
function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
{
// Output a cell
$k = $this->k;
if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())
{
// Automatic page break
$x = $this->x;
$ws = $this->ws;
if($ws>0)
{
$this->ws = 0;
$this->_out('0 Tw');
}
$this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation);
$this->x = $x;
if($ws>0)
{
$this->ws = $ws;
$this->_out(sprintf('%.3F Tw',$ws*$k));
}
}
if($w==0)
$w = $this->w-$this->rMargin-$this->x;
$s = '';
if($fill || $border==1)
{
if($fill)
$op = ($border==1) ? 'B' : 'f';
else
$op = 'S';
$s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
}
if(is_string($border))
{
$x = $this->x;
$y = $this->y;
if(strpos($border,'L')!==false)
$s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
if(strpos($border,'T')!==false)
$s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
if(strpos($border,'R')!==false)
$s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
if(strpos($border,'B')!==false)
$s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
}
if($txt!=='')
{
if(!isset($this->CurrentFont))
$this->Error('No font has been set');
if($align=='R')
$dx = $w-$this->cMargin-$this->GetStringWidth($txt);
elseif($align=='C')
$dx = ($w-$this->GetStringWidth($txt))/2;
else
$dx = $this->cMargin;
if($this->ColorFlag)
$s .= 'q '.$this->TextColor.' ';
$s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt));
if($this->underline)
$s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
if($this->ColorFlag)
$s .= ' Q';
if($link)
$this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link);
}
if($s)
$this->_out($s);
$this->lasth = $h;
if($ln>0)
{
// Go to next line
$this->y += $h;
if($ln==1)
$this->x = $this->lMargin;
}
else
$this->x += $w;
}
function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false)
{
// Output text with automatic or explicit line breaks
if(!isset($this->CurrentFont))
$this->Error('No font has been set');
$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(strpos($border,'L')!==false)
$b2 .= 'L';
if(strpos($border,'R')!==false)
$b2 .= 'R';
$b = (strpos($border,'T')!==false) ? $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;
$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($l>$wmax)
{
// Automatic line break
if($sep==-1)
{
if($i==$j)
$i++;
if($this->ws>0)
{
$this->ws = 0;
$this->_out('0 Tw');
}
$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;
$this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
}
$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;
}
else
$i++;
}
// Last chunk
if($this->ws>0)
{
$this->ws = 0;
$this->_out('0 Tw');
}
if($border && strpos($border,'B')!==false)
$b .= 'B';
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
$this->x = $this->lMargin;
}
function Write($h, $txt, $link='')
{
// Output text in flowing mode
if(!isset($this->CurrentFont))
$this->Error('No font has been set');
$cw = &$this->CurrentFont['cw'];
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
$s = str_replace("\r",'',$txt);
$nb = strlen($s);
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while($i<$nb)
{
// Get next character
$c = $s[$i];
if($c=="\n")
{
// Explicit line break
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link);
$i++;
$sep = -1;
$j = $i;
$l = 0;
if($nl==1)
{
$this->x = $this->lMargin;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
}
$nl++;
continue;
}
if($c==' ')
$sep = $i;
$l += $cw[$c];
if($l>$wmax)
{
// Automatic line break
if($sep==-1)
{
if($this->x>$this->lMargin)
{
// Move to next line
$this->x = $this->lMargin;
$this->y += $h;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
$i++;
$nl++;
continue;
}
if($i==$j)
$i++;
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link);
}
else
{
$this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link);
$i = $sep+1;
}
$sep = -1;
$j = $i;
$l = 0;
if($nl==1)
{
$this->x = $this->lMargin;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
}
$nl++;
}
else
$i++;
}
// Last chunk
if($i!=$j)
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link);
}
function Ln($h=null)
{
// Line feed; default value is the last cell height
$this->x = $this->lMargin;
if($h===null)
$this->y += $this->lasth;
else
$this->y += $h;
}
function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='')
{
// Put an image on the page
if($file=='')
$this->Error('Image file name is empty');
if(!isset($this->images[$file]))
{
// First use of this image, get info
if($type=='')
{
$pos = strrpos($file,'.');
if(!$pos)
$this->Error('Image file has no extension and no type was specified: '.$file);
$type = substr($file,$pos+1);
}
$type = strtolower($type);
if($type=='jpeg')
$type = 'jpg';
$mtd = '_parse'.$type;
if(!method_exists($this,$mtd))
$this->Error('Unsupported image type: '.$type);
$info = $this->$mtd($file);
$info['i'] = count($this->images)+1;
$this->images[$file] = $info;
}
else
$info = $this->images[$file];
// Automatic width and height calculation if needed
if($w==0 && $h==0)
{
// Put image at 96 dpi
$w = -96;
$h = -96;
}
if($w<0)
$w = -$info['w']*72/$w/$this->k;
if($h<0)
$h = -$info['h']*72/$h/$this->k;
if($w==0)
$w = $h*$info['w']/$info['h'];
if($h==0)
$h = $w*$info['h']/$info['w'];
// Flowing mode
if($y===null)
{
if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())
{
// Automatic page break
$x2 = $this->x;
$this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation);
$this->x = $x2;
}
$y = $this->y;
$this->y += $h;
}
if($x===null)
$x = $this->x;
$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']));
if($link)
$this->Link($x,$y,$w,$h,$link);
}
function GetPageWidth()
{
// Get current page width
return $this->w;
}
function GetPageHeight()
{
// Get current page height
return $this->h;
}
function GetX()
{
// Get x position
return $this->x;
}
function SetX($x)
{
// Set x position
if($x>=0)
$this->x = $x;
else
$this->x = $this->w+$x;
}
function GetY()
{
// Get y position
return $this->y;
}
function SetY($y, $resetX=true)
{
// Set y position and optionally reset x
if($y>=0)
$this->y = $y;
else
$this->y = $this->h+$y;
if($resetX)
$this->x = $this->lMargin;
}
function SetXY($x, $y)
{
// Set x and y positions
$this->SetX($x);
$this->SetY($y,false);
}
function Output($dest='', $name='', $isUTF8=false)
{
// Output PDF to some destination
$this->Close();
if(strlen($name)==1 && strlen($dest)!=1)
{
// Fix parameter order
$tmp = $dest;
$dest = $name;
$name = $tmp;
}
if($dest=='')
$dest = 'I';
if($name=='')
$name = 'doc.pdf';
switch(strtoupper($dest))
{
case 'I':
// Send to standard output
$this->_checkoutput();
if(PHP_SAPI!='cli')