tFPDF::Output PHP Метод

Output() публичный Метод

public Output ( $name = '', $dest = '' )
    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 '';
    }

Usage Example

Пример #1
0
 public function Output($name = '', $dest = '')
 {
     // invalid symbols: "%*:<>?| and \x00-\x1F\x7F and \x80-\xFF
     $name = preg_replace('/[\\x00-\\x1F\\x22\\x25\\x2A\\x3A\\x3C\\x3E\\x3F\\x7C\\x7F-\\xFF]+/', '', $name);
     $name = str_replace('\\', '/', $name);
     if (in_array($dest, array('I', 'D'))) {
         $name = basename($name);
     }
     return parent::Output($name, $dest);
 }
All Usage Examples Of tFPDF::Output