summaryrefslogtreecommitdiffstats
path: root/vendor/iio/libmergepdf/src/Driver
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/iio/libmergepdf/src/Driver
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/iio/libmergepdf/src/Driver')
-rw-r--r--vendor/iio/libmergepdf/src/Driver/DefaultDriver.php25
-rw-r--r--vendor/iio/libmergepdf/src/Driver/DriverInterface.php13
-rw-r--r--vendor/iio/libmergepdf/src/Driver/Fpdi2Driver.php64
-rw-r--r--vendor/iio/libmergepdf/src/Driver/TcpdiDriver.php52
4 files changed, 154 insertions, 0 deletions
diff --git a/vendor/iio/libmergepdf/src/Driver/DefaultDriver.php b/vendor/iio/libmergepdf/src/Driver/DefaultDriver.php
new file mode 100644
index 0000000..9ad6f73
--- /dev/null
+++ b/vendor/iio/libmergepdf/src/Driver/DefaultDriver.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types = 1);
+
+namespace iio\libmergepdf\Driver;
+
+use iio\libmergepdf\Source\SourceInterface;
+
+final class DefaultDriver implements DriverInterface
+{
+ /**
+ * @var DriverInterface
+ */
+ private $wrapped;
+
+ public function __construct(DriverInterface $wrapped = null)
+ {
+ $this->wrapped = $wrapped ?: new Fpdi2Driver;
+ }
+
+ public function merge(SourceInterface ...$sources): string
+ {
+ return $this->wrapped->merge(...$sources);
+ }
+}
diff --git a/vendor/iio/libmergepdf/src/Driver/DriverInterface.php b/vendor/iio/libmergepdf/src/Driver/DriverInterface.php
new file mode 100644
index 0000000..39cca1e
--- /dev/null
+++ b/vendor/iio/libmergepdf/src/Driver/DriverInterface.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace iio\libmergepdf\Driver;
+
+use iio\libmergepdf\Source\SourceInterface;
+
+interface DriverInterface
+{
+ /**
+ * Merge multiple sources
+ */
+ public function merge(SourceInterface ...$sources): string;
+}
diff --git a/vendor/iio/libmergepdf/src/Driver/Fpdi2Driver.php b/vendor/iio/libmergepdf/src/Driver/Fpdi2Driver.php
new file mode 100644
index 0000000..e56d8b1
--- /dev/null
+++ b/vendor/iio/libmergepdf/src/Driver/Fpdi2Driver.php
@@ -0,0 +1,64 @@
+<?php
+
+declare(strict_types = 1);
+
+namespace iio\libmergepdf\Driver;
+
+use iio\libmergepdf\Exception;
+use iio\libmergepdf\Source\SourceInterface;
+use setasign\Fpdi\Fpdi as FpdiFpdf;
+use setasign\Fpdi\Tcpdf\Fpdi as FpdiTcpdf;
+use setasign\Fpdi\PdfParser\StreamReader;
+
+final class Fpdi2Driver implements DriverInterface
+{
+ /**
+ * @var FpdiFpdf|FpdiTcpdf
+ */
+ private $fpdi;
+
+ /**
+ * @param FpdiFpdf|FpdiTcpdf $fpdi
+ */
+ public function __construct($fpdi = null)
+ {
+ // Tcpdf generates warnings due to argument ordering with php 8
+ // suppressing errors is a dirty hack until tcpdf is patched
+ $this->fpdi = $fpdi ?: @new FpdiTcpdf;
+
+ if (!($this->fpdi instanceof FpdiFpdf) && !($this->fpdi instanceof FpdiTcpdf)) {
+ throw new \InvalidArgumentException('Constructor argument must be an FPDI instance.');
+ }
+ }
+
+ public function merge(SourceInterface ...$sources): string
+ {
+ $sourceName = '';
+
+ try {
+ $fpdi = clone $this->fpdi;
+
+ foreach ($sources as $source) {
+ $sourceName = $source->getName();
+ $pageCount = $fpdi->setSourceFile(StreamReader::createByString($source->getContents()));
+ $pageNumbers = $source->getPages()->getPageNumbers() ?: range(1, $pageCount);
+
+ foreach ($pageNumbers as $pageNr) {
+ $template = $fpdi->importPage($pageNr);
+ $size = $fpdi->getTemplateSize($template);
+ $fpdi->SetPrintHeader(false);
+ $fpdi->SetPrintFooter(false);
+ $fpdi->AddPage(
+ $size['width'] > $size['height'] ? 'L' : 'P',
+ [$size['width'], $size['height']]
+ );
+ $fpdi->useTemplate($template);
+ }
+ }
+
+ return $fpdi->Output('', 'S');
+ } catch (\Exception $e) {
+ throw new Exception("'{$e->getMessage()}' in '$sourceName'", 0, $e);
+ }
+ }
+}
diff --git a/vendor/iio/libmergepdf/src/Driver/TcpdiDriver.php b/vendor/iio/libmergepdf/src/Driver/TcpdiDriver.php
new file mode 100644
index 0000000..fa0ddc8
--- /dev/null
+++ b/vendor/iio/libmergepdf/src/Driver/TcpdiDriver.php
@@ -0,0 +1,52 @@
+<?php
+
+declare(strict_types = 1);
+
+namespace iio\libmergepdf\Driver;
+
+use iio\libmergepdf\Exception;
+use iio\libmergepdf\Source\SourceInterface;
+
+final class TcpdiDriver implements DriverInterface
+{
+ /**
+ * @var \TCPDI
+ */
+ private $tcpdi;
+
+ public function __construct(\TCPDI $tcpdi = null)
+ {
+ $this->tcpdi = $tcpdi ?: new \TCPDI;
+ }
+
+ public function merge(SourceInterface ...$sources): string
+ {
+ $sourceName = '';
+
+ try {
+ $tcpdi = clone $this->tcpdi;
+
+ foreach ($sources as $source) {
+ $sourceName = $source->getName();
+ $pageCount = $tcpdi->setSourceData($source->getContents());
+ $pageNumbers = $source->getPages()->getPageNumbers() ?: range(1, $pageCount);
+
+ foreach ($pageNumbers as $pageNr) {
+ $template = $tcpdi->importPage($pageNr);
+ $size = $tcpdi->getTemplateSize($template);
+ $tcpdi->SetPrintHeader(false);
+ $tcpdi->SetPrintFooter(false);
+ $tcpdi->AddPage(
+ $size['w'] > $size['h'] ? 'L' : 'P',
+ [$size['w'], $size['h']]
+ );
+ $tcpdi->useTemplate($template);
+ }
+ }
+
+ return $tcpdi->Output('', 'S');
+ } catch (\Exception $e) {
+ throw new Exception("'{$e->getMessage()}' in '$sourceName'", 0, $e);
+ }
+ }
+}