Skip to content

Commit

Permalink
filigrane: conversion d'un svg filigrané en pdf final
Browse files Browse the repository at this point in the history
Reste à faire le svg 🙃
  • Loading branch information
gpoma committed Dec 13, 2024
1 parent a868b38 commit 946ae65
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function($f3) {
$f3->route('POST /sign',
function($f3) {
$filename = null;
$filigrane = $f3->get('POST.filigrane');
$tmpfile = tempnam($f3->get('UPLOADS'), 'pdfsignature_sign_'.uniqid("", true));
unlink($tmpfile);
$svgFiles = [];
Expand Down Expand Up @@ -215,6 +216,9 @@ function($f3) {

PDFSignature::createPDFFromSvg($svgFiles, $tmpfile.'.svg.pdf');
PDFSignature::addSvgToPDF($tmpfile.'.pdf', $tmpfile.'.svg.pdf', $tmpfile.'_signe.pdf');
if ($filigrane) {
PDFSignature::convertTextToFiligrane($filigrane, $tmpfile.'_signe.pdf');
}

Web::instance()->send($tmpfile.'_signe.pdf', null, 0, TRUE, $filename);

Expand Down
21 changes: 21 additions & 0 deletions lib/PDFSignature.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ public static function addSvgToPDF($pdfOrigin, $pdfSvg, $pdfOutput, $digitalSign
}
}

public static function convertTextToFiligrane($text, $outputFile)
{
// Création svg
// TODO

// conversion du filigrane en pdf
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s",
escapeshellarg($outputFile.'_filigrane.pdf'),
escapeshellarg($outputFile.'_filigrane.svg')
));

// on applique le filigrane
shell_exec(sprintf("pdftk %s background %s output %s",
escapeshellarg($outputFile),
escapeshellarg($outputFile.'_filigrane.pdf'),
escapeshellarg($outputFile.'_withfiligrane.pdf')
));

rename($outputFile.'_withfiligrane.pdf', $outputFile);
}

public function clean() {
foreach($this->toClean as $path) {
if(strpos($path, $this->pathHash) !== false) {
Expand Down

0 comments on commit 946ae65

Please sign in to comment.