function Output($name = '', $dest = '')
{
// Output PDF to some destination
if ($this->state < 3) {
$this->Close();
}
$dest = strtoupper($dest);
if ($dest == '') {
if ($name == '') {
$name = 'doc.pdf';
$dest = 'I';
} else {
$dest = 'F';
}
}
switch ($dest) {
case 'I':
// Send to standard output
$this->_checkoutput();
if (PHP_SAPI != 'cli') {
// We send to a browser
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $name . '"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
}
echo $this->buffer;
break;
case 'D':
// Download file
$this->_checkoutput();
header('Content-Type: application/x-download');
header('Content-Disposition: attachment; filename="' . $name . '"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
echo $this->buffer;
break;
case 'F':
// Save to local file
$f = fopen($name, 'wb');
if (!$f) {
$this->Error('Unable to create output file: ' . $name);
}
fwrite($f, $this->buffer, strlen($this->buffer));
fclose($f);
break;
case 'S':
// Return as a string
return $this->buffer;
default:
$this->Error('Incorrect output destination: ' . $dest);
}
return '';
}