1

I'm trying to generate a pdf file in a php code using fpdf. However when I'm running this code in the project, this is the output I get: FPDF error: Some data has already been output, can't send PDF file (output started at C:\xampp\htdocs\header.php:92). header.php is not the file in which this script is written. I tried using ob_clean(); and ob_end_flush();. But it doesn't work.

 <?php

    require("fpdf/fpdf.php");
    $pdf = new FPDF();
    global $DB;
    $orderID=$_REQUEST['garID'];
    $sql = "SELECT * FROM `" . $DB->pre . "garorder` WHERE garID= '" . $orderID . "'"; 
    $d = $DB->dbRow($sql);
    echo 'name:'.$d['orderdate'].' Party Code :'.$d['partyCode'];

    $pdf->AddPage();

            $pdf->Rect(5, 5, 200, 287, 'D');


             $pdf->Cell(10);
             $pdf->SetFont("Arial","B","8");
             $pdf->SetXY (10,30);
             $pdf->MultiCell(50,5,"  ",1,1);

    $pdf->Ln(); 

          $pdf->SetFont('helvetica','B',10);
          $pdf->Cell(190,7,'Order Details',1,2,'C');
          $pdf->SetFont('helvetica','',10);
          $y= $pdf->GetY();
          $pdf->MultiCell(95,8, "Garment ID: "."\nParty Code: "."\nOrder Date: " , 'LRB',1 );
          //$x= $pdf->GetX();
          //$pdf->setXY($x+95,$y);
          $pdf->Cell(90);
          $pdf->SetFont('helvetica','',10);
         $pdf->SetXY (105,62);
          $pdf->MultiCell(95,12, "Name: "."\nDelivery Status: " , 'LRB',1 );
      $pdf-> Ln();
         $pdf->Cell(32,10,'Material Description',1,0,'L',0);
         $period = 50;
         for($x=36;$x <=$period; $x=$x+2){

           $pdf->Cell(20,10,$x,1,0,'L',0);  



         }


    $pdf->Output();


    ?>
Hans Solo
  • 55
  • 3
  • 16
  • If it is saying that output started in header.php, then it sounds like your script is being run through some framework that already includes the header.php file automatically. How is your script being called? – zenzelezz May 04 '17 at 07:22

1 Answers1

0

remove

 echo 'name:'.$d['orderdate'].' Party Code :'.$d['partyCode'];

That will fix it.

or Add ob_start(); and ob_end_flush(); on the beginning and end respectively like this:

<?php
ob_start();
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
ob_end_flush(); 
?>

Here are few good examples FPDF error: Some data has already been output, can't send PDF

Community
  • 1
  • 1
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78