【问题标题】:PDF not download - FPDFPDF 不下载 - FPDF
【发布时间】:2020-12-05 03:00:41
【问题描述】:

我使用 FPDF 库通过 php 下载 pdf。

viewinspect

预览和响应选项卡中的此视图.. 但未下载。

这是我的代码

        $file = 'File.pdf';
       
        ob_clean();

        $pdf = new FPDF();

        $pdf->AddPage();
        $pdf->SetFont('Arial', 'B', 12);
        $pdf->SetMargins(2, 2, 2);

        $pdf->WriteHTML($post['txt']);
  
        $pdf->Output('I',$file);
        exit;

【问题讨论】:

  • 不要使用 AJAX。并使用D 作为目的地。

标签: php download fpdf


【解决方案1】:

改用“D”参数。 “I”参数会将文件内联发送到浏览器。 所以你的代码应该:

    $pdf->Output('D',$file);

【讨论】:

  • 我用过,还是一样
  • 之前可以手动设置header:$pdf->Output('D',$file);通过添加 header("Content-type:application/pdf"); header("Content-Disposition:attachment;filename='$file'");
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多