Skip to content
Snippets Groups Projects
Commit 3d46e510 authored by Jean-Laurent DUZANT's avatar Jean-Laurent DUZANT
Browse files

FIX #23967 TIME 0:45 implement check before adding a watermark

parent 806b6472
No related branches found
No related tags found
No related merge requests found
...@@ -60,10 +60,16 @@ class WatermarkController ...@@ -60,10 +60,16 @@ class WatermarkController
require_once($libPath); require_once($libPath);
} }
$fileContent = null;
try { try {
$watermarkFile = CoreConfigModel::getTmpPath() . "tmp_file_{$GLOBALS['id']}_" .rand(). "_watermark.pdf"; $watermarkFile = CoreConfigModel::getTmpPath() . "tmp_file_{$GLOBALS['id']}_" .rand(). "_watermark.pdf";
file_put_contents($watermarkFile, base64_decode($args['encodedDocument'])); file_put_contents($watermarkFile, base64_decode($args['encodedDocument']));
$isSigned = WatermarkController::checkDocumentSignatureField(['encodedDocument' => $args['encodedDocument']]);
if(!empty($isSigned)) {
return $fileContent;
}
$pdf = new Fpdi('P', 'pt'); $pdf = new Fpdi('P', 'pt');
$nbPages = $pdf->setSourceFile($watermarkFile); $nbPages = $pdf->setSourceFile($watermarkFile);
$pdf->setPrintHeader(false); $pdf->setPrintHeader(false);
...@@ -81,8 +87,40 @@ class WatermarkController ...@@ -81,8 +87,40 @@ class WatermarkController
$fileContent = $pdf->Output('', 'S'); $fileContent = $pdf->Output('', 'S');
} catch (\Exception $e) { } catch (\Exception $e) {
$fileContent = null; $fileContent = null;
var_dump($e);
} }
return $fileContent; return $fileContent;
} }
public static function checkDocumentSignatureField(array $args)
{
$libDir = CoreConfigModel::getLibrariesDirectory();
$alreadySigned = false;
if (!empty($libDir) && is_file($libDir . 'SetaPDF-FormFiller-Full/library/SetaPDF/Autoload.php')) {
require_once($libDir . 'SetaPDF-FormFiller-Full/library/SetaPDF/Autoload.php');
$targetFile = CoreConfigModel::getTmpPath() . "tmp_file_{$GLOBALS['id']}_" . rand() . "_target_watermark.pdf";
file_put_contents($targetFile, base64_decode($args['encodedDocument']));
$document = \SetaPDF_Core_Document::loadByFilename($targetFile);
$formFiller = new \SetaPDF_FormFiller($document);
$fields = $formFiller->getFields();
$allFields = $fields->getAll();
foreach ($allFields as $fieldValue) {
if ($fieldValue instanceof \SetaPDF_FormFiller_Field_Signature) {
$alreadySigned = true;
break;
}
}
// Release objects to free memory and cycled references.
// After calling this method the instance of $document is unusable!
$document->cleanUp();
unlink($targetFile);
}
return $alreadySigned;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment