append actual PDF after label, if possible

This commit is contained in:
Tomáš Mládek 2019-12-02 15:07:31 +01:00
parent 2483679625
commit 7065bee237
2 changed files with 19 additions and 1 deletions

View file

@ -25,7 +25,7 @@
: </span><?= $doc["HTMLDescription"] ?></p> : </span><?= $doc["HTMLDescription"] ?></p>
<?php endif; ?> <?php endif; ?>
<div class="doc-link"><span class="doc-link-intro">Get print label: </span> <div class="doc-link"><span class="doc-link-intro">Get (document with) print label: </span>
<a href="/label.php?id=<?= $doc["ID"] ?>">https://pile.sdbs.cz/label.php?id=<?= $doc["ID"] ?></a></div> <a href="/label.php?id=<?= $doc["ID"] ?>">https://pile.sdbs.cz/label.php?id=<?= $doc["ID"] ?></a></div>
<?php if (!empty($doc["URL"])): ?> <?php if (!empty($doc["URL"])): ?>

View file

@ -39,6 +39,24 @@ try {
$mpdf->showImageErrors = true; $mpdf->showImageErrors = true;
$mpdf->WriteHTML($front->render("_templates/label_template.php")); $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(); $mpdf->Output();
} catch (Exception $exception) { } catch (Exception $exception) {
http_response_code(500); ?> http_response_code(500); ?>