1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
class FPDF_TPL extends FPDF {
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
var $tpls = array();
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
var $tpl = 0;
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
var $_intpl = false;
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
var $tplprefix = "/TPL";
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
var $_res = array();
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
var $lastUsedTemplateData = array();
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
function beginTemplate($x = null, $y = null, $w = null, $h = null) {
|
77 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
78 |
|
|
$this->Error('This method is only usable with FPDF. Use TCPDF methods startTemplate() instead.');
|
79 |
|
|
return;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
if ($this->page <= 0)
|
83 |
|
|
$this->error("You have to add a page to fpdf first!");
|
84 |
|
|
|
85 |
|
|
if ($x == null)
|
86 |
|
|
$x = 0;
|
87 |
|
|
if ($y == null)
|
88 |
|
|
$y = 0;
|
89 |
|
|
if ($w == null)
|
90 |
|
|
$w = $this->w;
|
91 |
|
|
if ($h == null)
|
92 |
|
|
$h = $this->h;
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
$this->tpl++;
|
96 |
|
|
$tpl =& $this->tpls[$this->tpl];
|
97 |
|
|
$tpl = array(
|
98 |
|
|
'o_x' => $this->x,
|
99 |
|
|
'o_y' => $this->y,
|
100 |
|
|
'o_AutoPageBreak' => $this->AutoPageBreak,
|
101 |
|
|
'o_bMargin' => $this->bMargin,
|
102 |
|
|
'o_tMargin' => $this->tMargin,
|
103 |
|
|
'o_lMargin' => $this->lMargin,
|
104 |
|
|
'o_rMargin' => $this->rMargin,
|
105 |
|
|
'o_h' => $this->h,
|
106 |
|
|
'o_w' => $this->w,
|
107 |
|
|
'o_FontFamily' => $this->FontFamily,
|
108 |
|
|
'o_FontStyle' => $this->FontStyle,
|
109 |
|
|
'o_FontSizePt' => $this->FontSizePt,
|
110 |
|
|
'o_FontSize' => $this->FontSize,
|
111 |
|
|
'buffer' => '',
|
112 |
|
|
'x' => $x,
|
113 |
|
|
'y' => $y,
|
114 |
|
|
'w' => $w,
|
115 |
|
|
'h' => $h
|
116 |
|
|
);
|
117 |
|
|
|
118 |
|
|
$this->SetAutoPageBreak(false);
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
$this->h = $h;
|
122 |
|
|
$this->w = $w;
|
123 |
|
|
|
124 |
|
|
$this->_intpl = true;
|
125 |
|
|
$this->SetXY($x + $this->lMargin, $y + $this->tMargin);
|
126 |
|
|
$this->SetRightMargin($this->w - $w + $this->rMargin);
|
127 |
|
|
|
128 |
|
|
if ($this->CurrentFont) {
|
129 |
|
|
$fontkey = $this->FontFamily . $this->FontStyle;
|
130 |
|
|
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
131 |
|
|
|
132 |
|
|
$this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
return $this->tpl;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
function endTemplate() {
|
146 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
147 |
|
|
$args = func_get_args();
|
148 |
|
|
return call_user_func_array(array($this, 'TCPDF::endTemplate'), $args);
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
if ($this->_intpl) {
|
152 |
|
|
$this->_intpl = false;
|
153 |
|
|
$tpl =& $this->tpls[$this->tpl];
|
154 |
|
|
$this->SetXY($tpl['o_x'], $tpl['o_y']);
|
155 |
|
|
$this->tMargin = $tpl['o_tMargin'];
|
156 |
|
|
$this->lMargin = $tpl['o_lMargin'];
|
157 |
|
|
$this->rMargin = $tpl['o_rMargin'];
|
158 |
|
|
$this->h = $tpl['o_h'];
|
159 |
|
|
$this->w = $tpl['o_w'];
|
160 |
|
|
$this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']);
|
161 |
|
|
|
162 |
|
|
$this->FontFamily = $tpl['o_FontFamily'];
|
163 |
|
|
$this->FontStyle = $tpl['o_FontStyle'];
|
164 |
|
|
$this->FontSizePt = $tpl['o_FontSizePt'];
|
165 |
|
|
$this->FontSize = $tpl['o_FontSize'];
|
166 |
|
|
|
167 |
|
|
$fontkey = $this->FontFamily . $this->FontStyle;
|
168 |
|
|
if ($fontkey)
|
169 |
|
|
$this->CurrentFont =& $this->fonts[$fontkey];
|
170 |
|
|
|
171 |
|
|
return $this->tpl;
|
172 |
|
|
} else {
|
173 |
|
|
return false;
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
function useTemplate($tplidx, $_x = null, $_y = null, $_w = 0, $_h = 0) {
|
195 |
|
|
if ($this->page <= 0)
|
196 |
|
|
$this->error('You have to add a page first!');
|
197 |
|
|
|
198 |
|
|
if (!isset($this->tpls[$tplidx]))
|
199 |
|
|
$this->error('Template does not exist!');
|
200 |
|
|
|
201 |
|
|
if ($this->_intpl) {
|
202 |
|
|
$this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx];
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
$tpl =& $this->tpls[$tplidx];
|
206 |
|
|
$w = $tpl['w'];
|
207 |
|
|
$h = $tpl['h'];
|
208 |
|
|
|
209 |
|
|
if ($_x == null)
|
210 |
|
|
$_x = 0;
|
211 |
|
|
if ($_y == null)
|
212 |
|
|
$_y = 0;
|
213 |
|
|
|
214 |
|
|
$_x += $tpl['x'];
|
215 |
|
|
$_y += $tpl['y'];
|
216 |
|
|
|
217 |
|
|
$wh = $this->getTemplateSize($tplidx, $_w, $_h);
|
218 |
|
|
$_w = $wh['w'];
|
219 |
|
|
$_h = $wh['h'];
|
220 |
|
|
|
221 |
|
|
$tData = array(
|
222 |
|
|
'x' => $this->x,
|
223 |
|
|
'y' => $this->y,
|
224 |
|
|
'w' => $_w,
|
225 |
|
|
'h' => $_h,
|
226 |
|
|
'scaleX' => ($_w / $w),
|
227 |
|
|
'scaleY' => ($_h / $h),
|
228 |
|
|
'tx' => $_x,
|
229 |
|
|
'ty' => ($this->h - $_y - $_h),
|
230 |
|
|
'lty' => ($this->h - $_y - $_h) - ($this->h - $h) * ($_h / $h)
|
231 |
|
|
);
|
232 |
|
|
|
233 |
|
|
$this->_out(sprintf('q %.4F 0 0 %.4F %.4F %.4F cm', $tData['scaleX'], $tData['scaleY'], $tData['tx'] * $this->k, $tData['ty'] * $this->k));
|
234 |
|
|
$this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx));
|
235 |
|
|
|
236 |
|
|
$this->lastUsedTemplateData = $tData;
|
237 |
|
|
|
238 |
|
|
return array('w' => $_w, 'h' => $_h);
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
|
|
function getTemplateSize($tplidx, $_w = 0, $_h = 0) {
|
252 |
|
|
if (!isset($this->tpls[$tplidx]))
|
253 |
|
|
return false;
|
254 |
|
|
|
255 |
|
|
$tpl =& $this->tpls[$tplidx];
|
256 |
|
|
$w = $tpl['w'];
|
257 |
|
|
$h = $tpl['h'];
|
258 |
|
|
|
259 |
|
|
if ($_w == 0 and $_h == 0) {
|
260 |
|
|
$_w = $w;
|
261 |
|
|
$_h = $h;
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
if($_w == 0)
|
265 |
|
|
$_w = $_h * $w / $h;
|
266 |
|
|
if($_h == 0)
|
267 |
|
|
$_h = $_w * $h / $w;
|
268 |
|
|
|
269 |
|
|
return array("w" => $_w, "h" => $_h);
|
270 |
|
|
}
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
public function SetFont($family, $style = '', $size = 0) {
|
276 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
277 |
|
|
$args = func_get_args();
|
278 |
|
|
return call_user_func_array(array($this, 'TCPDF::SetFont'), $args);
|
279 |
|
|
}
|
280 |
|
|
|
281 |
|
|
parent::SetFont($family, $style, $size);
|
282 |
|
|
|
283 |
|
|
$fontkey = $this->FontFamily . $this->FontStyle;
|
284 |
|
|
|
285 |
|
|
if ($this->_intpl) {
|
286 |
|
|
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
287 |
|
|
} else {
|
288 |
|
|
$this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
289 |
|
|
}
|
290 |
|
|
}
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
function Image(
|
296 |
|
|
$file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false,
|
297 |
|
|
$dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false,
|
298 |
|
|
$hidden = false, $fitonpage = false, $alt = false, $altimgs = array()
|
299 |
|
|
) {
|
300 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
301 |
|
|
$args = func_get_args();
|
302 |
|
|
return call_user_func_array(array($this, 'TCPDF::Image'), $args);
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
$ret = parent::Image($file, $x, $y, $w, $h, $type, $link);
|
306 |
|
|
if ($this->_intpl) {
|
307 |
|
|
$this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file];
|
308 |
|
|
} else {
|
309 |
|
|
$this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
|
310 |
|
|
}
|
311 |
|
|
|
312 |
|
|
return $ret;
|
313 |
|
|
}
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false) {
|
321 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
322 |
|
|
$args = func_get_args();
|
323 |
|
|
return call_user_func_array(array($this, 'TCPDF::AddPage'), $args);
|
324 |
|
|
}
|
325 |
|
|
|
326 |
|
|
if ($this->_intpl)
|
327 |
|
|
$this->Error('Adding pages in templates isn\'t possible!');
|
328 |
|
|
|
329 |
|
|
parent::AddPage($orientation, $format);
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
function Link($x, $y, $w, $h, $link, $spaces = 0) {
|
336 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
337 |
|
|
$args = func_get_args();
|
338 |
|
|
return call_user_func_array(array($this, 'TCPDF::Link'), $args);
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
if ($this->_intpl)
|
342 |
|
|
$this->Error('Using links in templates aren\'t possible!');
|
343 |
|
|
|
344 |
|
|
parent::Link($x, $y, $w, $h, $link);
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
function AddLink() {
|
348 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
349 |
|
|
$args = func_get_args();
|
350 |
|
|
return call_user_func_array(array($this, 'TCPDF::AddLink'), $args);
|
351 |
|
|
}
|
352 |
|
|
|
353 |
|
|
if ($this->_intpl)
|
354 |
|
|
$this->Error('Adding links in templates aren\'t possible!');
|
355 |
|
|
return parent::AddLink();
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
function SetLink($link, $y = 0, $page = -1) {
|
359 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
360 |
|
|
$args = func_get_args();
|
361 |
|
|
return call_user_func_array(array($this, 'TCPDF::SetLink'), $args);
|
362 |
|
|
}
|
363 |
|
|
|
364 |
|
|
if ($this->_intpl)
|
365 |
|
|
$this->Error('Setting links in templates aren\'t possible!');
|
366 |
|
|
parent::SetLink($link, $y, $page);
|
367 |
|
|
}
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
function _putformxobjects() {
|
373 |
|
|
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
374 |
|
|
reset($this->tpls);
|
375 |
|
|
foreach($this->tpls AS $tplidx => $tpl) {
|
376 |
|
|
|
377 |
|
|
$p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
|
378 |
|
|
$this->_newobj();
|
379 |
|
|
$this->tpls[$tplidx]['n'] = $this->n;
|
380 |
|
|
$this->_out('<<'.$filter.'/Type /XObject');
|
381 |
|
|
$this->_out('/Subtype /Form');
|
382 |
|
|
$this->_out('/FormType 1');
|
383 |
|
|
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
|
384 |
|
|
|
385 |
|
|
$tpl['x'] * $this->k,
|
386 |
|
|
|
387 |
|
|
-$tpl['y'] * $this->k,
|
388 |
|
|
|
389 |
|
|
($tpl['w'] + $tpl['x']) * $this->k,
|
390 |
|
|
|
391 |
|
|
($tpl['h'] - $tpl['y']) * $this->k
|
392 |
|
|
));
|
393 |
|
|
|
394 |
|
|
if ($tpl['x'] != 0 || $tpl['y'] != 0) {
|
395 |
|
|
$this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',
|
396 |
|
|
-$tpl['x'] * $this->k * 2, $tpl['y'] * $this->k * 2
|
397 |
|
|
));
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
$this->_out('/Resources ');
|
401 |
|
|
|
402 |
|
|
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
403 |
|
|
if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
|
404 |
|
|
$this->_out('/Font <<');
|
405 |
|
|
foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
|
406 |
|
|
$this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
|
407 |
|
|
$this->_out('>>');
|
408 |
|
|
}
|
409 |
|
|
if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
|
410 |
|
|
isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
|
411 |
|
|
{
|
412 |
|
|
$this->_out('/XObject <<');
|
413 |
|
|
if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
|
414 |
|
|
foreach($this->_res['tpl'][$tplidx]['images'] as $image)
|
415 |
|
|
$this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
|
416 |
|
|
}
|
417 |
|
|
if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
|
418 |
|
|
foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl)
|
419 |
|
|
$this->_out($this->tplprefix . $i . ' ' . $tpl['n'] . ' 0 R');
|
420 |
|
|
}
|
421 |
|
|
$this->_out('>>');
|
422 |
|
|
}
|
423 |
|
|
$this->_out('>>');
|
424 |
|
|
|
425 |
|
|
$this->_out('/Length ' . strlen($p) . ' >>');
|
426 |
|
|
$this->_putstream($p);
|
427 |
|
|
$this->_out('endobj');
|
428 |
|
|
}
|
429 |
|
|
}
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
function _putimages() {
|
436 |
|
|
parent::_putimages();
|
437 |
|
|
$this->_putformxobjects();
|
438 |
|
|
}
|
439 |
|
|
|
440 |
|
|
function _putxobjectdict() {
|
441 |
|
|
parent::_putxobjectdict();
|
442 |
|
|
|
443 |
|
|
if (count($this->tpls)) {
|
444 |
|
|
foreach($this->tpls as $tplidx => $tpl) {
|
445 |
|
|
$this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n']));
|
446 |
|
|
}
|
447 |
|
|
}
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
|
451 |
|
|
|
452 |
|
|
|
453 |
|
|
function _out($s) {
|
454 |
|
|
if ($this->state == 2 && $this->_intpl) {
|
455 |
|
|
$this->tpls[$this->tpl]['buffer'] .= $s . "\n";
|
456 |
|
|
} else {
|
457 |
|
|
parent::_out($s);
|
458 |
|
|
}
|
459 |
|
|
}
|
460 |
|
|
}
|