From 2f7c1f5156420a293faffb44c45081532222fdc5 Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 16:05:45 +0200 Subject: [PATCH] save pdf for sharing mode --- app.php | 35 +++++++++++++++++++++++++++++++++++ templates/signature.html.php | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/app.php b/app.php index a83546b..af25c69 100644 --- a/app.php +++ b/app.php @@ -263,4 +263,39 @@ $f3->route('GET /signature/@hash/pdf', } ); +$f3->route('POST /signature/@hash/save', + function($f3) { + $targetDir = $f3->get('STORAGE').$f3->get('PARAMS.hash').'/'; + $f3->set('UPLOADS', $targetDir); + $tmpfile = tempnam($targetDir, 'pdfsignature_sign'); + unlink($tmpfile); + $svgFiles = ""; + + + $files = Web::instance()->receive(function($file,$formFieldName){ + if($formFieldName == "svg" && strpos(Web::instance()->mime($file['tmp_name'], true), 'image/svg+xml') !== 0) { + $f3->error(403); + } + return true; + }, false, function($fileBaseName, $formFieldName) use ($f3, $tmpfile, &$svgFiles) { + if($formFieldName == "svg") { + $svgFiles .= " ".$tmpfile."_".$fileBaseName; + return basename($tmpfile."_".$fileBaseName); + } + }); + + if(!$svgFiles) { + $f3->error(403); + } + + shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $tmpfile.'.svg.pdf', $svgFiles)); + + if(!$f3->get('DEBUG')) { + array_map('unlink', $svgFiles); + } + + $f3->reroute('/signature/'.$f3->get('PARAMS.hash')); + } +); + return $f3; diff --git a/templates/signature.html.php b/templates/signature.html.php index 54e955e..4aec855 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -85,6 +85,13 @@ + +
+ +
+ +
+