From 6c109acdbeb1153c5ba8ddb661e717c66c95c7cb Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 14:54:14 +0200 Subject: [PATCH 1/8] duplicate error --- app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.php b/app.php index e92cc92..d6068c3 100644 --- a/app.php +++ b/app.php @@ -227,7 +227,7 @@ $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('..', '.'));; + $files = array_diff(scandir($targetDir), array('..', '.')); $original = null; $originalFilename = null; $layers = []; From 0d81740d090266145a709a39a1d3ccf114055624 Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 14:55:45 +0200 Subject: [PATCH 2/8] improved files identification --- app.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app.php b/app.php index d6068c3..deda5f5 100644 --- a/app.php +++ b/app.php @@ -232,12 +232,15 @@ $f3->route('GET /signature/@hash/pdf', $originalFilename = null; $layers = []; foreach($files as $file) { - if (strpos($file, 'svg.pdf') === false) { - $original = $targetDir.'/'.$file; - $originalFilename = $file; - } else { - $layers[] = $targetDir.'/'.$file; + if (strpos($file, 'signe.pdf') !== false) { + continue; } + if(strpos($file, 'svg.pdf') !== false) { + $layers[] = $targetDir.'/'.$file; + continue; + } + $original = $targetDir.'/'.$file; + $originalFilename = $file; } if (!$original) { $f3->error(404); From b432256ccce7b7121685e505b286c43802671a5c Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 14:58:27 +0200 Subject: [PATCH 3/8] increase layer on original pdf with pdftk overlay --- app.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app.php b/app.php index deda5f5..925cc03 100644 --- a/app.php +++ b/app.php @@ -248,8 +248,13 @@ $f3->route('GET /signature/@hash/pdf', 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)); + $newFile = str_replace('.pdf', '_signe.pdf', $original); + $newFilename = str_replace('.pdf', '_signe.pdf', $originalFilename); + shell_exec(sprintf("pdftk %s multibackground %s output %s", $layers[0], $original, $newFile)); + for($i = 1, $max = count($layers); $i < $max; $i++) { + shell_exec(sprintf("pdftk %1\$s multibackground %2\$s output %3\$s && mv %3\$s %2\$s", $layers[$i], $newFile, str_replace('_signe.pdf', '_tmp_signe.pdf', $newFile))); + } + Web::instance()->send($newFile, null, 0, TRUE, $newFilename); } ); From be2d9a794cfaf1d2a5355633a9e87dabaa650ad9 Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 14:59:48 +0200 Subject: [PATCH 4/8] deleting generated file from server --- app.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app.php b/app.php index 925cc03..9fc0cd9 100644 --- a/app.php +++ b/app.php @@ -255,6 +255,11 @@ $f3->route('GET /signature/@hash/pdf', shell_exec(sprintf("pdftk %1\$s multibackground %2\$s output %3\$s && mv %3\$s %2\$s", $layers[$i], $newFile, str_replace('_signe.pdf', '_tmp_signe.pdf', $newFile))); } Web::instance()->send($newFile, null, 0, TRUE, $newFilename); + + if($f3->get('DEBUG')) { + return; + } + unlink($newFile); } ); From 6f8c2fb4edae8a789a794b2a969cc7f19020e44d Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 15:00:42 +0200 Subject: [PATCH 5/8] end of forcing --- app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.php b/app.php index 9fc0cd9..ac4f3aa 100644 --- a/app.php +++ b/app.php @@ -245,7 +245,7 @@ $f3->route('GET /signature/@hash/pdf', if (!$original) { $f3->error(404); } - if (!$layers||1==1) { + if (!$layers) { Web::instance()->send($original, null, 0, TRUE, str_replace('.pdf', '_signe.pdf', $originalFilename)); } $newFile = str_replace('.pdf', '_signe.pdf', $original); From c1c86fb88145b3b45c331acbf2beea842b3de774 Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 16:05:19 +0200 Subject: [PATCH 6/8] exclusive pdf file for treatment (for debug mode) --- app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.php b/app.php index ac4f3aa..a83546b 100644 --- a/app.php +++ b/app.php @@ -232,7 +232,7 @@ $f3->route('GET /signature/@hash/pdf', $originalFilename = null; $layers = []; foreach($files as $file) { - if (strpos($file, 'signe.pdf') !== false) { + if (strpos($file, '.pdf') === false || strpos($file, 'signe.pdf') !== false) { continue; } if(strpos($file, 'svg.pdf') !== false) { From 2f7c1f5156420a293faffb44c45081532222fdc5 Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 16:05:45 +0200 Subject: [PATCH 7/8] 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 @@ + +
+ +
+ +
+
From bb48a9acd85d977dd766af40674585e2d662ad33 Mon Sep 17 00:00:00 2001 From: Jb Lm Date: Thu, 31 Mar 2022 16:17:12 +0200 Subject: [PATCH 8/8] pdf download button for sharing mode --- templates/signature.html.php | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/signature.html.php b/templates/signature.html.php index 4aec855..904de74 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -86,6 +86,7 @@ + Télécharger le PDF