1
0
mirror of https://github.com/24eme/signaturepdf.git synced 2023-08-25 09:33:08 +02:00

add /signature/@hash/pdf route for concatenation of multiple signature

This commit is contained in:
Jb Lm 2022-03-31 12:15:26 +02:00
parent eb42a1547f
commit c452c32527

26
app.php
View File

@ -185,4 +185,30 @@ $f3->route('POST /organize',
}
);
$f3->route('GET /signature/@hash/pdf',
function($f3) {
$targetDir = $f3->get('STORAGE').$f3->get('PARAMS.hash');
$files = array_diff(scandir($targetDir), array('..', '.'));;
$original = null;
$originalFilename = null;
$layers = [];
foreach($files as $file) {
if (strpos($file, 'svg.pdf') === false) {
$original = $targetDir.'/'.$file;
$originalFilename = $file;
} else {
$layers[] = $targetDir.'/'.$file;
}
}
if (!$original) {
$f3->error(404);
}
if (!$layers||1==1) {
Web::instance()->send($original, null, 0, TRUE, str_replace('.pdf', '_signe.pdf', $originalFilename));
}
shell_exec(sprintf("pdftk %s multibackground %s output %s", implode(' ', $layers), $original, str_replace('.pdf', '_signe.pdf', $original)));
Web::instance()->send(str_replace('.pdf', '_signe.pdf', $original), null, 0, TRUE, str_replace('.pdf', '_signe.pdf', $originalFilename));
}
);
return $f3;