1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace Fpdi\PdfParser\CrossReference;
- use Fpdi\PdfParser\PdfParser;
- use Fpdi\PdfParser\Type\PdfDictionary;
- use Fpdi\PdfParser\Type\PdfToken;
- use Fpdi\PdfParser\Type\PdfTypeException;
- abstract class AbstractReader
- {
-
- protected $parser;
-
- protected $trailer;
-
- public function __construct(PdfParser $parser)
- {
- $this->parser = $parser;
- $this->readTrailer();
- }
-
- public function getTrailer()
- {
- return $this->trailer;
- }
-
- protected function readTrailer()
- {
- try {
- $trailerKeyword = $this->parser->readValue(null, PdfToken::class);
- if ($trailerKeyword->value !== 'trailer') {
- throw new CrossReferenceException(
- \sprintf(
- 'Unexpected end of cross reference. "trailer"-keyword expected, got: %s.',
- $trailerKeyword->value
- ),
- CrossReferenceException::UNEXPECTED_END
- );
- }
- } catch (PdfTypeException $e) {
- throw new CrossReferenceException(
- 'Unexpected end of cross reference. "trailer"-keyword expected, got an invalid object type.',
- CrossReferenceException::UNEXPECTED_END,
- $e
- );
- }
- try {
- $trailer = $this->parser->readValue(null, PdfDictionary::class);
- } catch (PdfTypeException $e) {
- throw new CrossReferenceException(
- 'Unexpected end of cross reference. Trailer not found.',
- CrossReferenceException::UNEXPECTED_END,
- $e
- );
- }
- $this->trailer = $trailer;
- }
- }
|