-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.php
97 lines (78 loc) · 2.2 KB
/
pdf.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
<?php
require './config/fpdf/fpdf.php';
class PDF extends FPDF {
var $widths;
var $aligns;
function SetWidths($w) {
$this->widths = $w;
}
function SetAligns($a) {
$this->aligns = $a;
}
function Row($data) {
$nb = 0;
for ($i = 0; $i < count($data); $i++)
$nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
$h = 5 * $nb;
$this->CheckPageBreak($h);
for ($i = 0; $i < count($data); $i++) {
$w = $this->widths[$i];
$a = isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
$x = $this->GetX();
$y = $this->GetY();
$this->Rect($x, $y, $w, $h);
$this->MultiCell($w, 5, $data[$i], 0, $a);
$this->SetXY($x + $w, $y);
}
$this->Ln($h);
}
function CheckPageBreak($h) {
if ($this->GetY() + $h > $this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}
function NbLines($w, $txt) {
$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 and $s[$nb - 1] == "\n")
$nb--;
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while ($i < $nb) {
$c = $s[$i];
if ($c == "\n") {
$i++;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
continue;
}
if ($c == ' ')
$sep = $i;
$l+= $cw[$c];
if ($l > $wmax) {
if ($sep == -1) {
if ($i == $j)
$i++;
}
else
$i = $sep + 1;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
}
else
$i++;
}
return $nl;
}
}
?>