Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
/**
4
 * This file is part of FPDI
5
 *
6
 * @package   setasign\Fpdi
7
 * @copyright Copyright (c) 2023 Setasign GmbH & Co. KG (https://www.setasign.com)
8
 * @license   http://opensource.org/licenses/mit-license The MIT License
9
 */
10
 
11
namespace setasign\Fpdi\PdfParser\CrossReference;
12
 
13
use setasign\Fpdi\PdfParser\PdfParser;
14
use setasign\Fpdi\PdfParser\Type\PdfDictionary;
15
use setasign\Fpdi\PdfParser\Type\PdfToken;
16
use setasign\Fpdi\PdfParser\Type\PdfTypeException;
17
 
18
/**
19
 * Abstract class for cross-reference reader classes.
20
 */
21
abstract class AbstractReader
22
{
23
    /**
24
     * @var PdfParser
25
     */
26
    protected $parser;
27
 
28
    /**
29
     * @var PdfDictionary
30
     */
31
    protected $trailer;
32
 
33
    /**
34
     * AbstractReader constructor.
35
     *
36
     * @param PdfParser $parser
37
     * @throws CrossReferenceException
38
     * @throws PdfTypeException
39
     */
40
    public function __construct(PdfParser $parser)
41
    {
42
        $this->parser = $parser;
43
        $this->readTrailer();
44
    }
45
 
46
    /**
47
     * Get the trailer dictionary.
48
     *
49
     * @return PdfDictionary
50
     */
51
    public function getTrailer()
52
    {
53
        return $this->trailer;
54
    }
55
 
56
    /**
57
     * Read the trailer dictionary.
58
     *
59
     * @throws CrossReferenceException
60
     * @throws PdfTypeException
61
     */
62
    protected function readTrailer()
63
    {
64
        try {
65
            $trailerKeyword = $this->parser->readValue(null, PdfToken::class);
66
            if ($trailerKeyword->value !== 'trailer') {
67
                throw new CrossReferenceException(
68
                    \sprintf(
69
                        'Unexpected end of cross reference. "trailer"-keyword expected, got: %s.',
70
                        $trailerKeyword->value
71
                    ),
72
                    CrossReferenceException::UNEXPECTED_END
73
                );
74
            }
75
        } catch (PdfTypeException $e) {
76
            throw new CrossReferenceException(
77
                'Unexpected end of cross reference. "trailer"-keyword expected, got an invalid object type.',
78
                CrossReferenceException::UNEXPECTED_END,
79
                $e
80
            );
81
        }
82
 
83
        try {
84
            $trailer = $this->parser->readValue(null, PdfDictionary::class);
85
        } catch (PdfTypeException $e) {
86
            throw new CrossReferenceException(
87
                'Unexpected end of cross reference. Trailer not found.',
88
                CrossReferenceException::UNEXPECTED_END,
89
                $e
90
            );
91
        }
92
 
93
        $this->trailer = $trailer;
94
    }
95
}