tcpdf在safari中生成pdf.html文档(Mac)

时间:2016-04-04 13:15:11

标签: php macos pdf safari tcpdf

Tcpdf在safari Mac中生成pdf as filename.pdf.html,它作为html文件加载而不是pdf文件。我应该设置哪些参数在safari中将其下载为pdf?

它在所有其他浏览器中运行良好。

这是我的功能:

$pdf_content = $libTcpdf->downloadReceipt((string) $view->render());
$pdf_content->Output("Receipt.pdf", 'D');

html页面存储在视图中。

在tcpdf.php(tcpdf库)

case 'D': {
    // download PDF as file
    if (ob_get_contents()) {
        $this->Error('Some data has already been output, can\'t send PDF file');
    }
    header('Content-Description: File Transfer');
    if (headers_sent()) {
        $this->Error('Some data has already been output to browser, can\'t send PDF file');
    }
    header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
    //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
    header('Pragma: public');
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    // force download dialog
    if (strpos(php_sapi_name(), 'cgi') === false) {
        header('Content-Type: application/force-download');
        header('Content-Type: application/octet-stream', false);
        header('Content-Type: application/download', false);
        header('Content-Type: application/pdf', false);
    } else {
        header('Content-Type: application/pdf');
    }
    // use the Content-Disposition header to supply a recommended filename
    header('Content-Disposition: attachment; filename="'.basename($name).'"');
    header('Content-Transfer-Encoding: binary');
    $this->sendOutputData($this->getBuffer(), $this->bufferlen);
    break;
}

Content-type设置为application / pdf。

0 个答案:

没有答案
相关问题