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
|
<?php
namespace Fisharebest\Webtrees\Report;
/**
* webtrees: online genealogy
* Copyright (C) 2015 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 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, see <http://www.gnu.org/licenses/>.
*/
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Media;
/**
* Class ReportPdf
*/
class ReportPdf extends ReportBase {
/**
* PDF compression - Zlib extension is required
*
* @var bool const
*/
const COMPRESSION = true;
/**
* If true reduce the RAM memory usage by caching temporary data on filesystem (slower).
*
* @var bool const
*/
const DISK_CACHE = false;
/**
* true means that the input text is unicode (PDF)
*
* @var bool const
*/
const UNICODE = true;
/**
* false means that the full font is embedded, true means only the used chars
* in TCPDF v5.9 font subsetting is a very slow process, this leads to larger files
*
* @var bool const
*/
const SUBSETTING = false;
/**
* A new object of the PDF class
*
* @var ReportTcpdf
*/
public $pdf;
/**
* PDF Setup - ReportPdf
*/
public function setup() {
parent::setup();
// Setup the PDF class with custom size pages because WT supports more page sizes. If WT sends an unknown size name then the default would be A4
$this->pdf = new ReportTcpdf($this->orientation, parent::UNITS, array(
$this->pagew,
$this->pageh,
), self::UNICODE, "UTF-8", self::DISK_CACHE);
// Setup the PDF margins
$this->pdf->setMargins($this->leftmargin, $this->topmargin, $this->rightmargin);
$this->pdf->SetHeaderMargin($this->headermargin);
$this->pdf->SetFooterMargin($this->footermargin);
//Set auto page breaks
$this->pdf->SetAutoPageBreak(true, $this->bottommargin);
// Set font subsetting
$this->pdf->setFontSubsetting(self::SUBSETTING);
// Setup PDF compression
$this->pdf->SetCompression(self::COMPRESSION);
// Setup RTL support
$this->pdf->setRTL($this->rtl);
// Set the document information
// Only admin should see the version number
$appversion = WT_WEBTREES;
if (Auth::isAdmin()) {
$appversion .= " " . WT_VERSION;
}
$this->pdf->SetCreator($appversion . " (" . parent::WT_URL . ")");
// Not implemented yet - ReportBase::setup()
$this->pdf->SetAuthor($this->rauthor);
$this->pdf->SetTitle($this->title);
$this->pdf->SetSubject($this->rsubject);
$this->pdf->SetKeywords($this->rkeywords);
$this->pdf->setReport($this);
if ($this->showGenText) {
// The default style name for Generated by.... is 'genby'
$element = new ReportPdfCell(0, 10, 0, "C", "", "genby", 1, ".", ".", 0, 0, "", "", true);
$element->addText($this->generatedby);
$element->setUrl(parent::WT_URL);
$this->pdf->addFooter($element);
}
}
/**
* Add an element - ReportPdf
*
* @param object|string $element Object or string
*
* @return int
*/
public function addElement($element) {
if ($this->processing == "B") {
return $this->pdf->addBody($element);
} elseif ($this->processing == "H") {
return $this->pdf->addHeader($element);
} elseif ($this->processing == "F") {
return $this->pdf->addFooter($element);
}
return 0;
}
/**
*
*/
public function run() {
$this->pdf->body();
header('Expires:');
header('Pragma:');
header('Cache-control:');
$this->pdf->Output('webtrees-' . uniqid() . '.pdf', 'I');
}
/**
* Clear the Header - ReportPdf
*/
public function clearHeader() {
$this->pdf->clearHeader();
}
/**
* Clear the Page Header - ReportPdf
*/
public function clearPageHeader() {
$this->pdf->clearPageHeader();
}
/**
* Create a new Cell object - ReportPdf
*
* @param int $width cell width (expressed in points)
* @param int $height cell height (expressed in points)
* @param mixed $border Border style
* @param string $align Text alignement
* @param string $bgcolor Background color code
* @param string $style The name of the text style
* @param int $ln Indicates where the current position should go after the call
* @param mixed $top Y-position
* @param mixed $left X-position
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 1
* @param int $stretch Stretch carachter mode
* @param string $bocolor Border color
* @param string $tcolor Text color
* @param bool $reseth
*
* @return ReportPdfCell
*/
public function createCell(
$width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth
) {
return new ReportPdfCell($width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth);
}
/**
* Create a new TextBox object - ReportPdf
*
* @param float $width Text box width
* @param float $height Text box height
* @param bool $border
* @param string $bgcolor Background color code in HTML
* @param bool $newline
* @param mixed $left
* @param mixed $top
* @param bool $pagecheck
* @param string $style
* @param bool $fill
* @param bool $padding
* @param bool $reseth
*
* @return ReportPdfTextbox
*/
public function createTextBox(
$width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth
) {
return new ReportPdfTextbox($width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth);
}
/**
* Create a new Text object- ReportPdf
*
* @param string $style The name of the text style
* @param string $color HTML color code
*
* @return ReportPdfText
*/
public function createText($style, $color) {
return new ReportPdfText($style, $color);
}
/**
* Create a new Footnote object - ReportPdf
*
* @param string $style Style name
*
* @return ReportPdfFootnote
*/
public function createFootnote($style) {
return new ReportPdfFootnote($style);
}
/**
* Create a new Page Header object - ReportPdf
*
* @return ReportPdfPageheader
*/
public function createPageHeader() {
return new ReportPdfPageheader;
}
/**
* Create a new image object - ReportPdf
*
* @param string $file Filename
* @param mixed $x
* @param mixed $y
* @param int $w Image width
* @param int $h Image height
* @param string $align L:left, C:center, R:right or empty to use x/y
* @param string $ln T:same line, N:next line
*
* @return ReportPdfImage
*/
public function createImage($file, $x, $y, $w, $h, $align, $ln) {
return new ReportPdfImage($file, $x, $y, $w, $h, $align, $ln);
}
/**
* Create a new image object from Media Object - ReportPdf
*
* @param Media $mediaobject
* @param mixed $x
* @param mixed $y
* @param int $w Image width
* @param int $h Image height
* @param string $align L:left, C:center, R:right or empty to use x/y
* @param string $ln T:same line, N:next line
*
* @return ReportPdfImage
*/
public function createImageFromObject($mediaobject, $x, $y, $w, $h, $align, $ln) {
return new ReportPdfImage($mediaobject->getServerFilename('thumb'), $x, $y, $w, $h, $align, $ln);
}
/**
* Create a new line object - ReportPdf
*
* @param mixed $x1
* @param mixed $y1
* @param mixed $x2
* @param mixed $y2
*
* @return ReportPdfLine
*/
public function createLine($x1, $y1, $x2, $y2) {
return new ReportPdfLine($x1, $y1, $x2, $y2);
}
/**
* @param $tag
* @param $attrs
*
* @return ReportPdfHtml
*/
public function createHTML($tag, $attrs) {
return new ReportPdfHtml($tag, $attrs);
}
}
|