/** * Output to HTTP response * * @param AbstractDocument $document * @param string $filename * @param boolean $forceDownload * @return string */ public function outputToHttp(AbstractDocument $document, $filename = 'pop.pdf', $forceDownload = false) { $headers = ['Content-type' => 'application/pdf', 'Content-disposition' => ($forceDownload ? 'attachment; ' : null) . 'filename=' . $filename]; if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) { $headers['Expires'] = 0; $headers['Cache-Control'] = 'private, must-revalidate'; $headers['Pragma'] = 'cache'; } $compiler = new Build\Compiler(); $compiler->finalize($document); // Send the headers and output the PDF if (!headers_sent()) { header('HTTP/1.1 200 OK'); foreach ($headers as $name => $value) { header($name . ': ' . $value); } } echo $compiler->getOutput(); }
/** * Output the PDF document to string * * @return string */ public function __toString() { $compiler = new Build\Compiler(); $compiler->finalize($this); return $compiler->getOutput(); }