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

La route pour sauvegardé un pdf signé n'a plus besoin du paramètre key

et le nom de fichier peut être récupéré depuis le champs d'upload
This commit is contained in:
Vincent LAURENT 2021-11-12 09:03:35 +01:00
parent 07acab564b
commit 84790c924c
4 changed files with 15 additions and 23 deletions

27
app.php
View File

@ -93,19 +93,20 @@ $f3->route('POST /image2svg',
array_map('unlink', glob($imageFile."*"));
}
);
$f3->route('POST /@key/save',
$f3->route('POST /sign',
function($f3) {
$key = $f3->get('PARAMS.key');
$filename = null;
$files = Web::instance()->receive(function($file,$formFieldName){
if(strpos(Web::instance()->mime($file['tmp_name'], true), 'application/pdf') !== 0) {
return false;
}
return true;
}, true, function($fileBaseName, $formFieldName) use ($key) {
return $key.".pdf";
}, true, function($fileBaseName, $formFieldName) use ($f3, &$filename) {
$filename = str_replace(".pdf", "_signe.pdf", $fileBaseName);
$tmpfile = tempnam($f3->get('UPLOADS'), 'pdfsignature_pdf');
unlink($tmpfile);
return basename($tmpfile).".pdf";
});
$pdfFile = null;
@ -121,27 +122,23 @@ $f3->route('POST /@key/save',
}
$svgData = $_POST['svg'];
$filename = null;
if(isset($_POST['filename']) && $_POST['filename']) {
$filename = str_replace(".pdf", "_signe.pdf", $_POST['filename']);
}
$svgFiles = "";
foreach($svgData as $index => $svgItem) {
$svgFile = $f3->get('UPLOADS').$key.'_'.$index.'.svg';
$svgFile = $pdfFile.'_'.$index.'.svg';
file_put_contents($svgFile, $svgItem);
$svgFiles .= $svgFile . " ";
}
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $f3->get('UPLOADS').$key.'.svg.pdf', $svgFiles));
shell_exec(sprintf("pdftk %s multibackground %s output %s", $f3->get('UPLOADS').$key.'.svg.pdf', $f3->get('UPLOADS').$key.'.pdf', $f3->get('UPLOADS').$key.'_signe.pdf'));
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $pdfFile.'.svg.pdf', $svgFiles));
shell_exec(sprintf("pdftk %s multibackground %s output %s", $pdfFile.'.svg.pdf', $pdfFile, $pdfFile.'_signe.pdf'));
Web::instance()->send($f3->get('UPLOADS').$key.'_signe.pdf', null, 0, TRUE, $filename);
Web::instance()->send($pdfFile.'_signe.pdf', null, 0, TRUE, $filename);
if($f3->get('DEBUG')) {
return;
}
array_map('unlink', glob($f3->get('UPLOADS').$key."*"));
array_map('unlink', glob($pdfFile."*"));
}
);

View File

@ -473,10 +473,6 @@ loadingTask.promise.then(function(pdf) {
xhr.send( formData );
}
if(filename) {
document.getElementById('input_filename').value = filename;
}
document.getElementById('save').addEventListener('click', function(event) {
canvasEditions.forEach(function(canvasEdition, index) {
document.getElementById('data-svg-'+index).value = canvasEdition.toSVG();

View File

@ -16,7 +16,7 @@
<div class="col-12">
<label for="input_pdf_upload" class="form-label">Choisir un PDF</label>
<input id="input_pdf_upload" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf">
<p><small class="text-muted">(Le PDF ne doit pas dépasser <?php echo round($maxSize / 1024 / 1024) ?> mo)</small></p>
<p><small class="text-muted">Le PDF ne doit pas dépasser <?php echo round($maxSize / 1024 / 1024) ?> Mo</small></p>
<a class="btn btn-sm btn-link opacity-75" href="/#https://raw.githubusercontent.com/24eme/signaturepdf/master/tests/files/document.pdf">Tester avec un PDF de démo</a>
</div>
</div>
@ -39,7 +39,7 @@
document.getElementById('input_pdf_upload').addEventListener('change', async function(event) {
if(document.getElementById('input_pdf_upload').files[0].size > maxSize) {
alert("Le PDF ne doit pas dépasser <?php echo round($maxSize / 1024 / 1024) ?> mo");
alert("Le PDF ne doit pas dépasser <?php echo round($maxSize / 1024 / 1024) ?> Mo");
document.getElementById('input_pdf_upload').value = "";
return;
}

View File

@ -68,8 +68,7 @@
<button type="button" id="btn-add-svg" class="btn btn-sm btn-light" data-bs-toggle="modal" data-bs-target="#modalAddSvg"><i class="bi bi-plus-circle"></i> Ajouter un élément</button>
</div>
<form class="position-absolute bottom-0 pb-2 ps-0 pe-4 w-100 d-none d-sm-none d-md-block" id="form_pdf" action="/<?php echo $key ?>/save" method="post" enctype="multipart/form-data">
<input id="input_filename" type="hidden" name="filename" value="" />
<form class="position-absolute bottom-0 pb-2 ps-0 pe-4 w-100 d-none d-sm-none d-md-block" id="form_pdf" action="/sign" method="post" enctype="multipart/form-data">
<input id="input_pdf" name="pdf" type="file" class="d-none" />
<div class="d-grid gap-2 mt-2">
<button class="btn btn-primary" disabled="disabled" type="submit" id="save"><i class="bi bi-download"></i> Télécharger le PDF Signé</button>