为什么fpdi pdf文件无法在Chrome中打开?

时间:2018-09-29 12:32:36

标签: php fpdf fpdi

我正在使用Drupal 8,在自定义模块中,我添加了fpdf(从http://www.fpdf.org/下载)和fpdi(从https://www.setasign.com/products/fpdi/downloads下载)。在控制器内部,我编写了pdf下载功能。

代码段:

use setasign\Fpdi\Fpdi;
require_once drupal_get_path('module', 'xxx') . '/fpdf/fpdf.php';
require_once drupal_get_path('module', 'xxx') . '/FPDI/autoload.php';

class WorkForm extends FormBase {
  function ...() {
    $downloadCount = 10;
    $fileRawPath = 'xxxxx';
    ob_start();
    $pdf = new Fpdi();
    $pdf->AddPage();
    $pdf->setSourceFile($fileRawPath);
    $tplIdx = $pdf->importPage(1);
    $pdf->useTemplate($tplIdx, 0, 0);
    $pdf->SetFont('Arial');
    $pdf->SetTextColor(255, 0, 0);
    $pdf->SetXY(185, 5);
    $pdf->Write(80, $downloadCount + 1);
    $pdf->SetXY(185, 5);
    $pdf->Write(180, $downloadCount + 1);
    $pdf->Output("application.pdf", 'D');
    ob_end_flush(); 
  }
}

上面的代码下载文件正确。但是下载的文件可以在Internet Explorer中打开,而不在chrome中打开? chrome错误提示“无法加载PDF文档”。上面的代码有问题吗?

0 个答案:

没有答案