PHP FPDF Failed to load PDF document in Chrome

I am trying to create a pdf document using the fpdf library with php, but I am getting an error in chrome like Failed to load PDF document. I can view the document correctly in firefox. Below is the code I'm trying to create pdf. Can anybody help? Thanks in advance.

<?php
 ini_set('display_startup_errors', 1);
 ini_set('display_errors', 1);
 error_reporting(-1);
 ob_start();
 $pdf = new FPDF();
 $pdf->AddPage();
 $pdf->SetFont('Arial', 'B', 16);
 $pdf->Cell(40, 10, 'Hello World!');
 header('Content-type: application/pdf');
 header('Content-Transfer-Encoding: binary');
 header("Content-Disposition: inline; filename='example2.pdf'");
 $pdf->Output('example2.pdf', 'I');
 ob_end_flush();
?>
+4
source share
1 answer

I know this old question, but there are requests for answers in the comments. Do not set the title. FPDF generates them.

<?php
   require('fpdf.php');

   $pdf = new FPDF();
   $pdf->AddPage();
   $pdf->SetFont('Arial','B',16);
   $pdf->Cell(40,10,'Hello World!');
   $pdf->Output('example2.pdf', 'I');
?>

I also recommend entering a link description here

0
source

All Articles