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

save pdf for sharing mode

This commit is contained in:
Jb Lm 2022-03-31 16:05:45 +02:00
parent c1c86fb881
commit 2f7c1f5156
2 changed files with 42 additions and 0 deletions

35
app.php
View File

@ -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; return $f3;

View File

@ -85,6 +85,13 @@
<button class="btn btn-primary" disabled="disabled" type="submit" id="save"><i class="bi bi-download"></i> Télécharger le PDF Signé</button> <button class="btn btn-primary" disabled="disabled" type="submit" id="save"><i class="bi bi-download"></i> Télécharger le PDF Signé</button>
</div> </div>
</form> </form>
<?php else: ?>
<form id="form_pdf" action="/signature/<?php echo $hash ?>/save" method="post" enctype="multipart/form-data">
<input id="input_svg" name="svg[]" 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-save"></i> Enregistrer ma signature</button>
</div>
</form>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>