Skip to content

Commit

Permalink
Merge pull request #195 from rafaelios/master
Browse files Browse the repository at this point in the history
Escapes binary path of wkhtmltopdf on windows
  • Loading branch information
ADmad committed Feb 23, 2017
2 parents 5790f9e + b0ee351 commit c492102
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Pdf/Engine/WkHtmlToPdfEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ class WkHtmlToPdfEngine extends AbstractPdfEngine
/**
* Path to the wkhtmltopdf executable binary
*
* @access protected
* @var string
*/
protected $_binary = '/usr/bin/wkhtmltopdf';

/**
* Flag to indicate if the environment is windows
*
* @var bool
*/
protected $_windowsEnvironment;

/**
* Constructor
*
Expand All @@ -23,6 +29,7 @@ class WkHtmlToPdfEngine extends AbstractPdfEngine
public function __construct(CakePdf $Pdf)
{
parent::__construct($Pdf);
$this->_windowsEnvironment = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}

/**
Expand Down Expand Up @@ -114,7 +121,12 @@ protected function _getCommand()
}
$options = array_merge($options, (array)$this->config('options'));

$command = $this->_binary;
if ($this->_windowsEnvironment) {
$command = '"' . $this->_binary . '"';
} else {
$command = $this->_binary;
}

foreach ($options as $key => $value) {
if (empty($value)) {
continue;
Expand All @@ -139,6 +151,10 @@ protected function _getCommand()
}
$command .= " - -";

if ($this->_windowsEnvironment) {
$command = '"' . $command . '"';
}

return $command;
}
}

0 comments on commit c492102

Please sign in to comment.