Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchParapheur
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchParapheur
Commits
3d46e510
Commit
3d46e510
authored
2 years ago
by
Jean-Laurent DUZANT
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/document/controllers/WatermarkController.php
+38
-0
38 additions, 0 deletions
src/app/document/controllers/WatermarkController.php
with
38 additions
and
0 deletions
src/app/document/controllers/WatermarkController.php
+
38
−
0
View file @
3d46e510
...
@@ -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
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment