Fpdf Error: Some Data Has Already Been Output, Can't Send Pdf

FPDF error: Some data has already been output, can't send PDF

For fpdf to work properly, there cannot be any output at all beside what fpdf generates. For example, this will work:

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

While this will not (note the leading space before the opening <? tag)

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

Also, this will not work either (the echo will break it):

<?php
echo "About to create pdf";
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

I'm not sure about the drupal side of things, but I know that absolutely zero non-fpdf output is a requirement for fpdf to work.

FPDF error: Some data has already been output, can't send PDF file on 000webhost

I think that session.auto_start is set to 1. This will start a session and send a PHPSESSID cookie to the browser.

You can try to disable it using the following code:

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

In case setting session.auto_start to 0 does not work, then try 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();
?>

FPDF Error Some data has already been output

Try this

  <?php
require('fpdf/fpdf.php');
ob_end_clean(); // the buffer and never prints or returns anything.
ob_start(); // it starts buffering
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
ob_end_flush(); // It's printed here, because ob_end_flush "prints" what's in
// the buffer, rather than returning it
// (unlike the ob_get_* functions)
?>

FPDF error: Some data has already been output, can't send PDF file

Some editors adds BOM at the start of a file.

View your file in hex and remove it

Some data has already been output, can't send PDF file

put if isset on your code. ie

if(isset($_POST['submitpdf']))
{
//$id=$_POST['id'];
//your code goes here
}

this is to ensure that your code would only run after reading your form-data

EDIT:

your new error i guess comes from the select string.

$pdf->Table('select leave_id, fullname, type_of_leave from application where     id_no="$_POST[id]"',$prop);

change it to this:

$pdf->Table("select leave_id, fullname, type_of_leave from application where id_no=".$_POST[id],$prop);


Related Topics



Leave a reply



Submit