X-Git-Url: http://git.roojs.org/?p=app.webkitpdf;a=blobdiff_plain;f=webkitpdf.php;h=4c470b51e303e4f487026ab73dc2ef2ada23b8f6;hp=1a95700b26cd67661646176ff5df1e39243ff16f;hb=6b7b2b4323346c940cabdbae507c20c0548098ac;hpb=d2ff91e9e0d1b306fa0a9c589091c3983e59c116 diff --git a/webkitpdf.php b/webkitpdf.php index 1a95700..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,15 @@ 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 " . $out . ' '; $res = `$cmd`; - if (!file_exist($out)) { + if (!file_exists($out)) { $this->h404("Failed to create file $cmd ==> $res"); } @@ -69,22 +71,14 @@ class WebkitPdf 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", $ts) . " GMT"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); - header('Content-length: '. filesize($out)); - header('Content-Disposition: '.$type.'; filename="' . htmlspecialchars($filename). '"'); + //header('Content-length: '. filesize($out)); + header('Content-Disposition: attachment; filename="' . htmlspecialchars(basename($out)). '"'); ini_set('display_errors', 0); $fh = fopen($out, 'rb'); - //fpassthru($fh); - - // passthrough seems to have problems -- trying fread - while(!feof($fh)) - { - echo @fread($fh, 1024*8); - ob_flush(); - flush(); - } + fpassthru($fh); fclose($fh); @@ -97,7 +91,9 @@ class WebkitPdf function h404($msg) { - + header("HTTP/1.0 404 Not Found"); + echo htmlspecialchars($msg); + exit; } } \ No newline at end of file