1 |
60370e04
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
if (!class_exists('FPDF_TPL')) {
|
21 |
|
|
require_once('fpdf_tpl.php');
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
class FPDI extends FPDF_TPL
|
28 |
|
|
{
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
const VERSION = '1.5.3';
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
public $currentFilename;
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
public $parsers = array();
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
public $currentParser;
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
public $lastUsedPageBox;
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
protected $_objStack;
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
protected $_doneObjStack;
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
protected $_currentObjId;
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
protected $_importedPages = array();
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
public function setSourceFile($filename)
|
102 |
|
|
{
|
103 |
|
|
$_filename = realpath($filename);
|
104 |
|
|
if (false !== $_filename)
|
105 |
|
|
$filename = $_filename;
|
106 |
|
|
|
107 |
|
|
$this->currentFilename = $filename;
|
108 |
|
|
|
109 |
|
|
if (!isset($this->parsers[$filename])) {
|
110 |
|
|
$this->parsers[$filename] = $this->_getPdfParser($filename);
|
111 |
|
|
$this->setPdfVersion(
|
112 |
|
|
max($this->getPdfVersion(), $this->parsers[$filename]->getPdfVersion())
|
113 |
|
|
);
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
$this->currentParser = $this->parsers[$filename];
|
117 |
|
|
|
118 |
|
|
return $this->parsers[$filename]->getPageCount();
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
protected function _getPdfParser($filename)
|
128 |
|
|
{
|
129 |
|
|
if (!class_exists('fpdi_pdf_parser')) {
|
130 |
|
|
require_once('fpdi_pdf_parser.php');
|
131 |
|
|
}
|
132 |
|
|
return new fpdi_pdf_parser($filename);
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
public function getPdfVersion()
|
141 |
|
|
{
|
142 |
|
|
return $this->PDFVersion;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
public function setPdfVersion($version = '1.3')
|
151 |
|
|
{
|
152 |
|
|
$this->PDFVersion = sprintf('%.1F', $version);
|
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 |
|
|
public function importPage($pageNo, $boxName = 'CropBox', $groupXObject = true)
|
181 |
|
|
{
|
182 |
|
|
if ($this->_inTpl) {
|
183 |
|
|
throw new LogicException('Please import the desired pages before creating a new template.');
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
$fn = $this->currentFilename;
|
187 |
|
|
$boxName = '/' . ltrim($boxName, '/');
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
$pageKey = $fn . '-' . ((int)$pageNo) . $boxName;
|
191 |
|
|
if (isset($this->_importedPages[$pageKey])) {
|
192 |
|
|
return $this->_importedPages[$pageKey];
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
$parser = $this->parsers[$fn];
|
196 |
|
|
$parser->setPageNo($pageNo);
|
197 |
|
|
|
198 |
|
|
if (!in_array($boxName, $parser->availableBoxes)) {
|
199 |
|
|
throw new InvalidArgumentException(sprintf('Unknown box: %s', $boxName));
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
$pageBoxes = $parser->getPageBoxes($pageNo, $this->k);
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
if (!isset($pageBoxes[$boxName]) && ($boxName == '/BleedBox' || $boxName == '/TrimBox' || $boxName == '/ArtBox'))
|
212 |
|
|
$boxName = '/CropBox';
|
213 |
|
|
if (!isset($pageBoxes[$boxName]) && $boxName == '/CropBox')
|
214 |
|
|
$boxName = '/MediaBox';
|
215 |
|
|
|
216 |
|
|
if (!isset($pageBoxes[$boxName]))
|
217 |
|
|
return false;
|
218 |
|
|
|
219 |
|
|
$this->lastUsedPageBox = $boxName;
|
220 |
|
|
|
221 |
|
|
$box = $pageBoxes[$boxName];
|
222 |
|
|
|
223 |
|
|
$this->tpl++;
|
224 |
|
|
$this->_tpls[$this->tpl] = array();
|
225 |
|
|
$tpl =& $this->_tpls[$this->tpl];
|
226 |
|
|
$tpl['parser'] = $parser;
|
227 |
|
|
$tpl['resources'] = $parser->getPageResources();
|
228 |
|
|
$tpl['buffer'] = $parser->getContent();
|
229 |
|
|
$tpl['box'] = $box;
|
230 |
|
|
$tpl['groupXObject'] = $groupXObject;
|
231 |
|
|
if ($groupXObject) {
|
232 |
|
|
$this->setPdfVersion(max($this->getPdfVersion(), 1.4));
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
$this->_tpls[$this->tpl] = array_merge($this->_tpls[$this->tpl], $box);
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
$tpl['x'] = 0;
|
240 |
|
|
$tpl['y'] = 0;
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
$rotation = $parser->getPageRotation($pageNo);
|
244 |
|
|
$tpl['_rotationAngle'] = 0;
|
245 |
|
|
if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0) {
|
246 |
|
|
$steps = $angle / 90;
|
247 |
|
|
|
248 |
|
|
$_w = $tpl['w'];
|
249 |
|
|
$_h = $tpl['h'];
|
250 |
|
|
$tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
|
251 |
|
|
$tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
|
252 |
|
|
|
253 |
|
|
if ($angle < 0)
|
254 |
|
|
$angle += 360;
|
255 |
|
|
|
256 |
|
|
$tpl['_rotationAngle'] = $angle * -1;
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
$this->_importedPages[$pageKey] = $this->tpl;
|
260 |
|
|
|
261 |
|
|
return $this->tpl;
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
|
|
public function getLastUsedPageBox()
|
270 |
|
|
{
|
271 |
|
|
return $this->lastUsedPageBox;
|
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 |
|
|
public function useTemplate($tplIdx, $x = null, $y = null, $w = 0, $h = 0, $adjustPageSize = false)
|
297 |
|
|
{
|
298 |
|
|
if ($adjustPageSize == true && is_null($x) && is_null($y)) {
|
299 |
|
|
$size = $this->getTemplateSize($tplIdx, $w, $h);
|
300 |
|
|
$orientation = $size['w'] > $size['h'] ? 'L' : 'P';
|
301 |
|
|
$size = array($size['w'], $size['h']);
|
302 |
|
|
|
303 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
304 |
|
|
$this->setPageFormat($size, $orientation);
|
305 |
|
|
} else {
|
306 |
|
|
$size = $this->_getpagesize($size);
|
307 |
|
|
|
308 |
|
|
if($orientation != $this->CurOrientation ||
|
309 |
|
|
$size[0] != $this->CurPageSize[0] ||
|
310 |
|
|
$size[1] != $this->CurPageSize[1]
|
311 |
|
|
) {
|
312 |
|
|
|
313 |
|
|
if ($orientation=='P') {
|
314 |
|
|
$this->w = $size[0];
|
315 |
|
|
$this->h = $size[1];
|
316 |
|
|
} else {
|
317 |
|
|
$this->w = $size[1];
|
318 |
|
|
$this->h = $size[0];
|
319 |
|
|
}
|
320 |
|
|
$this->wPt = $this->w * $this->k;
|
321 |
|
|
$this->hPt = $this->h * $this->k;
|
322 |
|
|
$this->PageBreakTrigger = $this->h - $this->bMargin;
|
323 |
|
|
$this->CurOrientation = $orientation;
|
324 |
|
|
$this->CurPageSize = $size;
|
325 |
|
|
$this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
|
326 |
|
|
}
|
327 |
|
|
}
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
$this->_out('q 0 J 1 w 0 j 0 G 0 g');
|
331 |
|
|
$size = parent::useTemplate($tplIdx, $x, $y, $w, $h);
|
332 |
|
|
$this->_out('Q');
|
333 |
|
|
|
334 |
|
|
return $size;
|
335 |
|
|
}
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
|
|
protected function _putimportedobjects()
|
341 |
|
|
{
|
342 |
|
|
foreach($this->parsers AS $filename => $p) {
|
343 |
|
|
$this->currentParser = $p;
|
344 |
|
|
if (!isset($this->_objStack[$filename]) || !is_array($this->_objStack[$filename])) {
|
345 |
|
|
continue;
|
346 |
|
|
}
|
347 |
|
|
while(($n = key($this->_objStack[$filename])) !== null) {
|
348 |
|
|
try {
|
349 |
|
|
$nObj = $this->currentParser->resolveObject($this->_objStack[$filename][$n][1]);
|
350 |
|
|
} catch (Exception $e) {
|
351 |
|
|
$nObj = array(pdf_parser::TYPE_OBJECT, pdf_parser::TYPE_NULL);
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
$this->_newobj($this->_objStack[$filename][$n][0]);
|
355 |
|
|
|
356 |
|
|
if ($nObj[0] == pdf_parser::TYPE_STREAM) {
|
357 |
|
|
$this->_writeValue($nObj);
|
358 |
|
|
} else {
|
359 |
|
|
$this->_writeValue($nObj[1]);
|
360 |
|
|
}
|
361 |
|
|
|
362 |
|
|
$this->_out("\nendobj");
|
363 |
|
|
$this->_objStack[$filename][$n] = null;
|
364 |
|
|
unset($this->_objStack[$filename][$n]);
|
365 |
|
|
reset($this->_objStack[$filename]);
|
366 |
|
|
}
|
367 |
|
|
}
|
368 |
|
|
}
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
|
|
protected function _putformxobjects()
|
374 |
|
|
{
|
375 |
|
|
$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
|
376 |
|
|
reset($this->_tpls);
|
377 |
|
|
foreach($this->_tpls AS $tplIdx => $tpl) {
|
378 |
|
|
$this->_newobj();
|
379 |
|
|
$currentN = $this->n;
|
380 |
|
|
|
381 |
|
|
$this->_tpls[$tplIdx]['n'] = $this->n;
|
382 |
|
|
$this->_out('<<' . $filter . '/Type /XObject');
|
383 |
|
|
$this->_out('/Subtype /Form');
|
384 |
|
|
$this->_out('/FormType 1');
|
385 |
|
|
|
386 |
|
|
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
|
387 |
|
|
(isset($tpl['box']['llx']) ? $tpl['box']['llx'] : $tpl['x']) * $this->k,
|
388 |
|
|
(isset($tpl['box']['lly']) ? $tpl['box']['lly'] : -$tpl['y']) * $this->k,
|
389 |
|
|
(isset($tpl['box']['urx']) ? $tpl['box']['urx'] : $tpl['w'] + $tpl['x']) * $this->k,
|
390 |
|
|
(isset($tpl['box']['ury']) ? $tpl['box']['ury'] : $tpl['h'] - $tpl['y']) * $this->k
|
391 |
|
|
));
|
392 |
|
|
|
393 |
|
|
$c = 1;
|
394 |
|
|
$s = 0;
|
395 |
|
|
$tx = 0;
|
396 |
|
|
$ty = 0;
|
397 |
|
|
|
398 |
|
|
if (isset($tpl['box'])) {
|
399 |
|
|
$tx = -$tpl['box']['llx'];
|
400 |
|
|
$ty = -$tpl['box']['lly'];
|
401 |
|
|
|
402 |
|
|
if ($tpl['_rotationAngle'] <> 0) {
|
403 |
|
|
$angle = $tpl['_rotationAngle'] * M_PI/180;
|
404 |
|
|
$c = cos($angle);
|
405 |
|
|
$s = sin($angle);
|
406 |
|
|
|
407 |
|
|
switch($tpl['_rotationAngle']) {
|
408 |
|
|
case -90:
|
409 |
|
|
$tx = -$tpl['box']['lly'];
|
410 |
|
|
$ty = $tpl['box']['urx'];
|
411 |
|
|
break;
|
412 |
|
|
case -180:
|
413 |
|
|
$tx = $tpl['box']['urx'];
|
414 |
|
|
$ty = $tpl['box']['ury'];
|
415 |
|
|
break;
|
416 |
|
|
case -270:
|
417 |
|
|
$tx = $tpl['box']['ury'];
|
418 |
|
|
$ty = -$tpl['box']['llx'];
|
419 |
|
|
break;
|
420 |
|
|
}
|
421 |
|
|
}
|
422 |
|
|
} else if ($tpl['x'] != 0 || $tpl['y'] != 0) {
|
423 |
|
|
$tx = -$tpl['x'] * 2;
|
424 |
|
|
$ty = $tpl['y'] * 2;
|
425 |
|
|
}
|
426 |
|
|
|
427 |
|
|
$tx *= $this->k;
|
428 |
|
|
$ty *= $this->k;
|
429 |
|
|
|
430 |
|
|
if ($c != 1 || $s != 0 || $tx != 0 || $ty != 0) {
|
431 |
|
|
$this->_out(sprintf('/Matrix [%.5F %.5F %.5F %.5F %.5F %.5F]',
|
432 |
|
|
$c, $s, -$s, $c, $tx, $ty
|
433 |
|
|
));
|
434 |
|
|
}
|
435 |
|
|
|
436 |
|
|
$this->_out('/Resources ');
|
437 |
|
|
|
438 |
|
|
if (isset($tpl['resources'])) {
|
439 |
|
|
$this->currentParser = $tpl['parser'];
|
440 |
|
|
$this->_writeValue($tpl['resources']);
|
441 |
|
|
} else {
|
442 |
|
|
|
443 |
|
|
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
444 |
|
|
if (isset($this->_res['tpl'][$tplIdx])) {
|
445 |
|
|
$res = $this->_res['tpl'][$tplIdx];
|
446 |
|
|
|
447 |
|
|
if (isset($res['fonts']) && count($res['fonts'])) {
|
448 |
|
|
$this->_out('/Font <<');
|
449 |
|
|
foreach ($res['fonts'] as $font)
|
450 |
|
|
$this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
|
451 |
|
|
$this->_out('>>');
|
452 |
|
|
}
|
453 |
|
|
if (isset($res['images']) && count($res['images']) ||
|
454 |
|
|
isset($res['tpls']) && count($res['tpls']))
|
455 |
|
|
{
|
456 |
|
|
$this->_out('/XObject <<');
|
457 |
|
|
if (isset($res['images'])) {
|
458 |
|
|
foreach ($res['images'] as $image)
|
459 |
|
|
$this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
|
460 |
|
|
}
|
461 |
|
|
if (isset($res['tpls'])) {
|
462 |
|
|
foreach ($res['tpls'] as $i => $_tpl)
|
463 |
|
|
$this->_out($this->tplPrefix . $i . ' ' . $_tpl['n'] . ' 0 R');
|
464 |
|
|
}
|
465 |
|
|
$this->_out('>>');
|
466 |
|
|
}
|
467 |
|
|
$this->_out('>>');
|
468 |
|
|
}
|
469 |
|
|
}
|
470 |
|
|
|
471 |
|
|
if (isset($tpl['groupXObject']) && $tpl['groupXObject']) {
|
472 |
|
|
$this->_out('/Group <</Type/Group/S/Transparency>>');
|
473 |
|
|
}
|
474 |
|
|
|
475 |
|
|
$newN = $this->n;
|
476 |
|
|
$this->n = $currentN;
|
477 |
|
|
|
478 |
|
|
$buffer = ($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
|
479 |
|
|
|
480 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
481 |
|
|
$buffer = $this->_getrawstream($buffer);
|
482 |
|
|
$this->_out('/Length ' . strlen($buffer) . ' >>');
|
483 |
|
|
$this->_out("stream\n" . $buffer . "\nendstream");
|
484 |
|
|
} else {
|
485 |
|
|
$this->_out('/Length ' . strlen($buffer) . ' >>');
|
486 |
|
|
$this->_putstream($buffer);
|
487 |
|
|
}
|
488 |
|
|
$this->_out('endobj');
|
489 |
|
|
$this->n = $newN;
|
490 |
|
|
}
|
491 |
|
|
|
492 |
|
|
$this->_putimportedobjects();
|
493 |
|
|
}
|
494 |
|
|
|
495 |
|
|
|
496 |
|
|
|
497 |
|
|
|
498 |
|
|
|
499 |
|
|
|
500 |
|
|
|
501 |
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
public function _newobj($objId = false, $onlyNewObj = false)
|
505 |
|
|
{
|
506 |
|
|
if (!$objId) {
|
507 |
|
|
$objId = ++$this->n;
|
508 |
|
|
}
|
509 |
|
|
|
510 |
|
|
|
511 |
|
|
if (!$onlyNewObj) {
|
512 |
|
|
$this->offsets[$objId] = is_subclass_of($this, 'TCPDF') ? $this->bufferlen : strlen($this->buffer);
|
513 |
|
|
$this->_out($objId . ' 0 obj');
|
514 |
|
|
$this->_currentObjId = $objId;
|
515 |
|
|
}
|
516 |
|
|
|
517 |
|
|
return $objId;
|
518 |
|
|
}
|
519 |
|
|
|
520 |
|
|
|
521 |
|
|
|
522 |
|
|
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
|
|
|
527 |
|
|
protected function _writeValue(&$value)
|
528 |
|
|
{
|
529 |
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
530 |
|
|
parent::_prepareValue($value);
|
531 |
|
|
}
|
532 |
|
|
|
533 |
|
|
switch ($value[0]) {
|
534 |
|
|
|
535 |
|
|
case pdf_parser::TYPE_TOKEN:
|
536 |
|
|
$this->_straightOut($value[1] . ' ');
|
537 |
|
|
break;
|
538 |
|
|
case pdf_parser::TYPE_NUMERIC:
|
539 |
|
|
case pdf_parser::TYPE_REAL:
|
540 |
|
|
if (is_float($value[1]) && $value[1] != 0) {
|
541 |
|
|
$this->_straightOut(rtrim(rtrim(sprintf('%F', $value[1]), '0'), '.') . ' ');
|
542 |
|
|
} else {
|
543 |
|
|
$this->_straightOut($value[1] . ' ');
|
544 |
|
|
}
|
545 |
|
|
break;
|
546 |
|
|
|
547 |
|
|
case pdf_parser::TYPE_ARRAY:
|
548 |
|
|
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
|
552 |
|
|
$this->_straightOut('[');
|
553 |
|
|
for ($i = 0; $i < count($value[1]); $i++) {
|
554 |
|
|
$this->_writeValue($value[1][$i]);
|
555 |
|
|
}
|
556 |
|
|
|
557 |
|
|
$this->_out(']');
|
558 |
|
|
break;
|
559 |
|
|
|
560 |
|
|
case pdf_parser::TYPE_DICTIONARY:
|
561 |
|
|
|
562 |
|
|
|
563 |
|
|
$this->_straightOut('<<');
|
564 |
|
|
|
565 |
|
|
reset ($value[1]);
|
566 |
|
|
|
567 |
|
|
while (list($k, $v) = each($value[1])) {
|
568 |
|
|
$this->_straightOut($k . ' ');
|
569 |
|
|
$this->_writeValue($v);
|
570 |
|
|
}
|
571 |
|
|
|
572 |
|
|
$this->_straightOut('>>');
|
573 |
|
|
break;
|
574 |
|
|
|
575 |
|
|
case pdf_parser::TYPE_OBJREF:
|
576 |
|
|
|
577 |
|
|
|
578 |
|
|
|
579 |
|
|
$cpfn =& $this->currentParser->filename;
|
580 |
|
|
if (!isset($this->_doneObjStack[$cpfn][$value[1]])) {
|
581 |
|
|
$this->_newobj(false, true);
|
582 |
|
|
$this->_objStack[$cpfn][$value[1]] = array($this->n, $value);
|
583 |
|
|
$this->_doneObjStack[$cpfn][$value[1]] = array($this->n, $value);
|
584 |
|
|
}
|
585 |
|
|
$objId = $this->_doneObjStack[$cpfn][$value[1]][0];
|
586 |
|
|
|
587 |
|
|
$this->_out($objId . ' 0 R');
|
588 |
|
|
break;
|
589 |
|
|
|
590 |
|
|
case pdf_parser::TYPE_STRING:
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
$this->_straightOut('(' . $value[1] . ')');
|
594 |
|
|
|
595 |
|
|
break;
|
596 |
|
|
|
597 |
|
|
case pdf_parser::TYPE_STREAM:
|
598 |
|
|
|
599 |
|
|
|
600 |
|
|
|
601 |
|
|
|
602 |
|
|
$this->_writeValue($value[1]);
|
603 |
|
|
$this->_out('stream');
|
604 |
|
|
$this->_out($value[2][1]);
|
605 |
|
|
$this->_straightOut("endstream");
|
606 |
|
|
break;
|
607 |
|
|
|
608 |
|
|
case pdf_parser::TYPE_HEX:
|
609 |
|
|
$this->_straightOut('<' . $value[1] . '>');
|
610 |
|
|
break;
|
611 |
|
|
|
612 |
|
|
case pdf_parser::TYPE_BOOLEAN:
|
613 |
|
|
$this->_straightOut($value[1] ? 'true ' : 'false ');
|
614 |
|
|
break;
|
615 |
|
|
|
616 |
|
|
case pdf_parser::TYPE_NULL:
|
617 |
|
|
|
618 |
|
|
|
619 |
|
|
$this->_straightOut('null ');
|
620 |
|
|
break;
|
621 |
|
|
}
|
622 |
|
|
}
|
623 |
|
|
|
624 |
|
|
|
625 |
|
|
|
626 |
|
|
|
627 |
|
|
|
628 |
|
|
protected function _straightOut($s)
|
629 |
|
|
{
|
630 |
|
|
if (!is_subclass_of($this, 'TCPDF')) {
|
631 |
|
|
if ($this->state == 2) {
|
632 |
|
|
$this->pages[$this->page] .= $s;
|
633 |
|
|
} else {
|
634 |
|
|
$this->buffer .= $s;
|
635 |
|
|
}
|
636 |
|
|
|
637 |
|
|
} else {
|
638 |
|
|
if ($this->state == 2) {
|
639 |
|
|
if ($this->inxobj) {
|
640 |
|
|
|
641 |
|
|
$this->xobjects[$this->xobjid]['outdata'] .= $s;
|
642 |
|
|
} else if ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
|
643 |
|
|
|
644 |
|
|
$pagebuff = $this->getPageBuffer($this->page);
|
645 |
|
|
$page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
|
646 |
|
|
$footer = substr($pagebuff, -$this->footerlen[$this->page]);
|
647 |
|
|
$this->setPageBuffer($this->page, $page . $s . $footer);
|
648 |
|
|
|
649 |
|
|
$this->footerpos[$this->page] += strlen($s);
|
650 |
|
|
} else {
|
651 |
|
|
|
652 |
|
|
$this->setPageBuffer($this->page, $s, true);
|
653 |
|
|
}
|
654 |
|
|
} else if ($this->state > 0) {
|
655 |
|
|
|
656 |
|
|
$this->setBuffer($s);
|
657 |
|
|
}
|
658 |
|
|
}
|
659 |
|
|
}
|
660 |
|
|
|
661 |
|
|
|
662 |
|
|
|
663 |
|
|
|
664 |
|
|
|
665 |
|
|
|
666 |
|
|
public function _enddoc()
|
667 |
|
|
{
|
668 |
|
|
parent::_enddoc();
|
669 |
|
|
$this->_closeParsers();
|
670 |
|
|
}
|
671 |
|
|
|
672 |
|
|
|
673 |
|
|
|
674 |
|
|
|
675 |
|
|
|
676 |
|
|
|
677 |
|
|
protected function _closeParsers()
|
678 |
|
|
{
|
679 |
|
|
if ($this->state > 2) {
|
680 |
|
|
$this->cleanUp();
|
681 |
|
|
return true;
|
682 |
|
|
}
|
683 |
|
|
|
684 |
|
|
return false;
|
685 |
|
|
}
|
686 |
|
|
|
687 |
|
|
|
688 |
|
|
|
689 |
|
|
|
690 |
|
|
public function cleanUp()
|
691 |
|
|
{
|
692 |
|
|
while (($parser = array_pop($this->parsers)) !== null) {
|
693 |
|
|
|
694 |
|
|
|
695 |
|
|
|
696 |
|
|
$parser->closeFile();
|
697 |
|
|
}
|
698 |
|
|
}
|
699 |
|
|
} |