PDF which name has space(s) would fail the command execution
ohchiko opened this issue · 0 comments
ohchiko commented
Problem
Generating watermark on a PDF document which name has space(s) fails the command execution. I have not try this on a Word file.
Reproduce
$document = 'pdf doc with spaces.pdf';
WatermarkFactory::load($document)->setText('simple watermark')->generate(); // returns empty string instead
Temporary Solution
Using escapeshellarg()
PHP function on getCommand()
function on Yasapurnama\DocumentWatermark\PDFWatermark
class.
// Yasapurnama\DocumentWatermark\PDFWatermark
...
if ($this->image) {
return sprintf(
'%s %s %s %s %s %s',
$this->getBinExecutable(),
escapeshellarg($this->documentPath), // escape the path as shell argument
escapeshellarg($this->image), // escape the path as shell argument
escapeshellarg($this->outputFile), // escape the path as shell argument
$this->getPositionOption(),
$this->getOpacityOption()
);
}
return sprintf(
'%s %s "%s" %s %s %s %s',
$this->getBinExecutable(),
escapeshellarg($this->documentPath), // escape the path as shell argument
$this->text,
escapeshellarg($this->outputFile), // escape the path as shell argument
$this->getFontColorOption(),
$this->getFontSizeOption(),
$this->getPositionOption()
);
...