X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=webkitpdf.php;h=4c470b51e303e4f487026ab73dc2ef2ada23b8f6;hb=0e5193e6109c8f251dcb4b9f0e9ee07ff6dd664e;hp=c8683a05872d06a47cae35c45f4b90c30a549905;hpb=65c03c7821c97a165ce453bc0428b32e2d734407;p=app.webkitpdf diff --git a/webkitpdf.php b/webkitpdf.php index c8683a0..4c470b5 100644 --- a/webkitpdf.php +++ b/webkitpdf.php @@ -35,7 +35,7 @@ class WebkitPdf $this->h404("missing timeout"); } - $xvfb = System::which('xvfb'); + $xvfb = System::which('xvfb-run'); if (empty($xvfb)) { $this->h404("missing xvfb"); } @@ -54,13 +54,46 @@ class WebkitPdf unlink($outpr); $out = $outpr .'.pdf'; - $cmd = "timeout 30s $xvfb --auto-servernum $webkitpdf " . + // can take 2-5 minutes... + + $cmd = "timeout 300s $xvfb --auto-servernum $webkitpdf " . " --url " . escapeshellarg($_REQUEST['url']) . ' ' . - " --pdf " . $tmpfile . ' '; + " --pdf " . $out . ' '; + $res = `$cmd`; + + if (!file_exists($out)) { + $this->h404("Failed to create file $cmd ==> $res"); + } + + header('Content-type: application/octet-stream'); + + header("Expires: "); + header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); + header("Pragma: public"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); + + //header('Content-length: '. filesize($out)); + header('Content-Disposition: attachment; filename="' . htmlspecialchars(basename($out)). '"'); + ini_set('display_errors', 0); + $fh = fopen($out, 'rb'); + fpassthru($fh); + + fclose($fh); + + + unlink($out); + exit; } + function h404($msg) + { + header("HTTP/1.0 404 Not Found"); + echo htmlspecialchars($msg); + exit; + } + } \ No newline at end of file