From 7065bee237a186b949e5a5281ec66e5adbe16543 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?=
Date: Mon, 2 Dec 2019 15:07:31 +0100
Subject: [PATCH] append actual PDF after label, if possible
---
www/_templates/front_doc_overview.php | 2 +-
www/label.php | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/www/_templates/front_doc_overview.php b/www/_templates/front_doc_overview.php
index 7325e72..d5c0b15 100644
--- a/www/_templates/front_doc_overview.php
+++ b/www/_templates/front_doc_overview.php
@@ -25,7 +25,7 @@
: = $doc["HTMLDescription"] ?>
- Get print label:
+
diff --git a/www/label.php b/www/label.php
index 2c94d61..319a85c 100644
--- a/www/label.php
+++ b/www/label.php
@@ -39,6 +39,24 @@ try {
$mpdf->showImageErrors = true;
$mpdf->WriteHTML($front->render("_templates/label_template.php"));
+ try {
+ if (preg_match('#^https?://pile.sdbs.cz/.*\.(pdf|PDF)$#', $doc['URL']) === 1) {
+ $tempName = tempnam("/tmp/", 'pile-merge');
+ file_put_contents($tempName, file_get_contents($doc["URL"]));
+ $pageCount = $mpdf->SetSourceFile($tempName);
+
+ for ($page = 1; $page <= $pageCount; $page++) {
+ $mpdf->AddPage();
+ $template = $mpdf->ImportPage($page);
+ $mpdf->UseTemplate($template);
+ }
+ }
+ } catch (Exception $exception) {
+ // noop
+ } finally {
+ unlink($tempName);
+ }
+
$mpdf->Output();
} catch (Exception $exception) {
http_response_code(500); ?>