Created
October 28, 2015 09:24
-
-
Save pulponair/3b9f3a59840cb8993de3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function generatePdfFromHtml($html) { | |
$descriptorSpecification = array( | |
0 => array('pipe', 'r'), // stdin | |
1 => array('pipe', 'w'), // stdout | |
2 => array('pipe', 'w'), // stderr | |
); | |
$process = proc_open($this->wkhtmltopdf . ' ' . implode(' ', $this->wkhtmltopdfParameters). ' - -', | |
$descriptorSpecification, $pipes); | |
fwrite($pipes[0], $html); | |
fclose($pipes[0]); | |
$pdf = stream_get_contents($pipes[1]); | |
$errors = stream_get_contents($pipes[2]); | |
fclose($pipes[1]); | |
$returnCode = proc_close($process); | |
if ($returnCode != 0 && $errors) { | |
throw new \Exception('PDF generation failed: ' . $errors); | |
} | |
return $pdf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment