forked from emaijala/MLInvoice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf.php
180 lines (174 loc) · 5.77 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
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
<?php
/**
* Extended TCPDF class
*
* PHP version 5
*
* Copyright (C) Ere Maijala 2010-2017.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category MLInvoice
* @package Printing
* @author Ere Maijala <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
use Michelf\Markdown;
/**
* Extended TCPDF class
*
* @category MLInvoice
* @package Printing
* @author Ere Maijala <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
class PDF extends TCPDF
{
public $headerLeft = '', $headerCenter = '', $headerRight = '';
public $footerLeft = '', $footerCenter = '', $footerRight = '';
public $printHeaderOnFirstPage = false;
public $printFooterOnFirstPage = false;
public $headerLeftPos = 4;
public $headerRightPos = 143;
public $footerLeftPos = 4;
public $footerRightPos = 143;
public $markdown = false;
/**
* This method is used to render the page header.
* It is automatically called by AddPage().
*
* @return void
*/
// @codingStandardsIgnoreLine
public function Header()
{
if ($this->PageNo() == 1 && !$this->printHeaderOnFirstPage) {
return;
}
$this->SetY(10);
$this->SetFont('Helvetica', '', 7);
$this->SetX($this->headerLeftPos);
$this->MultiCell(
120, 5, $this->handlePageNum($this->headerLeft), 0, 'L', 0, 0
);
$this->SetX(75);
$this->MultiCell(
65, 5, $this->handlePageNum($this->headerCenter), 0, 'C', 0, 0
);
$this->SetX($this->headerRightPos);
$this->MultiCell(
60, 5, $this->handlePageNum($this->headerRight), 0, 'R', 0, 0
);
}
/**
* This method is used to render the page footer.
* It is automatically called by AddPage().
*
* @return void
*/
// @codingStandardsIgnoreLine
public function Footer()
{
if ($this->PageNo() == 1 && !$this->printFooterOnFirstPage) {
return;
}
$this->SetY(-17);
$this->SetFont('Helvetica', '', 7);
$this->SetX($this->footerLeftPos);
$this->MultiCell(120, 5, $this->footerLeft, 0, 'L', 0, 0);
$this->SetX(75);
$this->MultiCell(65, 5, $this->footerCenter, 0, 'C', 0, 0);
$this->SetX($this->footerRightPos);
$this->MultiCell(60, 5, $this->footerRight, 0, 'R', 0, 0);
}
/**
* MultiCell with Markdown support.
*
* 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 />
* Text can be aligned, centered or justified. The cell block can be framed and
* the background painted.
*
* @param float $w (float) Width of cells. If 0, they extend up to the
* right margin of the page.
* @param float $h (float) Cell minimum height. The cell extends
* automatically if needed.
* @param string $txt (string) String to print
* @param string $align (string) 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
* when $ishtml=false)</li></ul>
* @param int $ln (int) 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 [DEFAULT]</li><li>2: below</li></ul>
* @param float $maxh (float) maximum height. It should be >= $h and less
* then remaining space to the bottom of the page, or 0 for disable this feature.
* This feature works only when $ishtml=false.
* @param bool $md Whether the input is to be interpreted as Markdown.
*
* @return int Return the number of cells or 1 for html mode.
*/
public function multiCellMD($w, $h, $txt, $align = 'J', $ln = 1,
$maxh = 0, $md = false
) {
if (!$md || !$this->markdown) {
$this->MultiCell(
$w,
$h,
$txt,
0,
$align,
false,
$ln,
'',
'',
true,
0,
false,
true,
$maxh
);
} else {
$html = Markdown::defaultTransform($txt);
$this->writeHTMLCell(
$w,
$h,
'',
'',
$html,
0,
$ln,
false,
true,
$align,
true
);
}
}
/**
* Include page number in a header string if appropriate
*
* @param string $str Header string
*
* @return string
*/
protected function handlePageNum($str)
{
return sprintf($str, $this->PageNo());
}
}