public static function respondPdf($responseID, $responseData = array()) { if (!empty($_REQUEST['downloadToken'])) { setcookie('downloadToken', $_REQUEST['downloadToken'], time() + 300, '/'); } $tmpPath = tempnam('/tmp', 'e_pdf_'); file_put_contents($tmpPath . '.html', Emergence\Dwoo\Engine::getSource("{$responseID}.pdf", $responseData)); header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . str_replace('"', '', $responseID) . '.pdf"'); exec(static::$wkhtmltopdfPath . " \"{$tmpPath}.html\" \"{$tmpPath}.pdf\""); if (!file_exists("{$tmpPath}.pdf")) { header('HTTP/1.0 501 Not Implemented'); die('Unable to generate PDF, check that this system has wkhtmltopdf installed'); } readfile($tmpPath . '.pdf'); exit; }