summaryrefslogtreecommitdiffstats
path: root/vendor/setasign/fpdi/src/PdfParser/CrossReference/AbstractReader.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:45:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:45:49 +0000
commit0ff39c83d38ce538a9f5dba53eca0fa9cb16d9e6 (patch)
tree84c735df2e97350a721273e9dd425729d43cc8a2 /vendor/setasign/fpdi/src/PdfParser/CrossReference/AbstractReader.php
parentInitial commit. (diff)
downloadicingaweb2-module-pdfexport-0ff39c83d38ce538a9f5dba53eca0fa9cb16d9e6.tar.xz
icingaweb2-module-pdfexport-0ff39c83d38ce538a9f5dba53eca0fa9cb16d9e6.zip
Adding upstream version 0.10.2+dfsg1.upstream/0.10.2+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/setasign/fpdi/src/PdfParser/CrossReference/AbstractReader.php')
-rw-r--r--vendor/setasign/fpdi/src/PdfParser/CrossReference/AbstractReader.php95
1 files changed, 95 insertions, 0 deletions
diff --git a/vendor/setasign/fpdi/src/PdfParser/CrossReference/AbstractReader.php b/vendor/setasign/fpdi/src/PdfParser/CrossReference/AbstractReader.php
new file mode 100644
index 0000000..b54237b
--- /dev/null
+++ b/vendor/setasign/fpdi/src/PdfParser/CrossReference/AbstractReader.php
@@ -0,0 +1,95 @@
+<?php
+
+/**
+ * This file is part of FPDI
+ *
+ * @package setasign\Fpdi
+ * @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
+ * @license http://opensource.org/licenses/mit-license The MIT License
+ */
+
+namespace setasign\Fpdi\PdfParser\CrossReference;
+
+use setasign\Fpdi\PdfParser\PdfParser;
+use setasign\Fpdi\PdfParser\Type\PdfDictionary;
+use setasign\Fpdi\PdfParser\Type\PdfToken;
+use setasign\Fpdi\PdfParser\Type\PdfTypeException;
+
+/**
+ * Abstract class for cross-reference reader classes.
+ */
+abstract class AbstractReader
+{
+ /**
+ * @var PdfParser
+ */
+ protected $parser;
+
+ /**
+ * @var PdfDictionary
+ */
+ protected $trailer;
+
+ /**
+ * AbstractReader constructor.
+ *
+ * @param PdfParser $parser
+ * @throws CrossReferenceException
+ * @throws PdfTypeException
+ */
+ public function __construct(PdfParser $parser)
+ {
+ $this->parser = $parser;
+ $this->readTrailer();
+ }
+
+ /**
+ * Get the trailer dictionary.
+ *
+ * @return PdfDictionary
+ */
+ public function getTrailer()
+ {
+ return $this->trailer;
+ }
+
+ /**
+ * Read the trailer dictionary.
+ *
+ * @throws CrossReferenceException
+ * @throws PdfTypeException
+ */
+ 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;
+ }
+}