3

I'm using fpdf in creating pdf in php and I'm getting this error when running:

Notice: Undefined index: id in C:\xampp1\htdocs\arvin2\public\pdf2\id.php on line 3
FPDF error: Some data has already been output, can't send PDF file

This is my php code (report.php):

<form action="http://localhost/pdf2/id.php" method="post" target="_blank">
<input type="text" name="id">
<input type="submit" name="submitpdf" value="Print"/>
</form>

the other one(eto.php):

<?php
require('mysql_table.php');
$id=$_POST['id'];

class PDF extends PDF_MySQL_Table
{
function Header()
{
//Title
$this->SetFont('Arial','',18);
$this->Cell(0,6,'Type of Leave',0,1,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}

mysql_connect('localhost','root','');
mysql_select_db('auth');


$pdf=new PDF();
//First table: put all columns automatically
$pdf->AddPage();
//Second table: specify 3 columns
$pdf->AddCol('leave_id',20,'','C');
$pdf->AddCol('fullname',40,'Fullname');
$pdf->AddCol('type_of_leave',40,'Type of Leave','R');
$prop=array('HeaderColor'=>array(255,150,100),
        'color1'=>array(210,245,255),
        'color2'=>array(255,255,210),
        'padding'=>2);
$pdf->Table('select leave_id, fullname, type_of_leave from application where     id_no="$_POST[id]"',$prop);
$pdf->Output();

?>

When I put:

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

The error says:

Parse error: syntax error, unexpected '$pdf' (T_VARIABLE) in C:\xampp1\htdocs\arvin2\public\pdf2\id.php on line 34

The output should be all the info of ID numbers inputted in the text field printed in the pdf form.

4

4 回答 4

1

I have got the same error.

Data has already been sent to output, unable to output PDF file

This means before creating pdf with mPDF some data is stored in the buffer which is sended to the browser. Therefore it is unable to create PDF.

Just do this.. Add this below php built-in function at the first line of your page were you are preparing data for pdf.

op_start();

And add this below php built-in function before mPDF code (before where you are calling mpdf)

ob_end_flush();

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output();

So that it will clear all buffer output before processing mPDF.

于 2020-09-10T06:46:33.330 回答
0

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);
于 2015-01-14T07:37:31.383 回答
0

You should use before the data you want to output in pdf.

ob_start();

Then use ob_end_clean().

ob_end_clean();
$pdf->Output(time().'.pdf', 'D')
于 2020-10-28T07:01:05.557 回答
-1

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

You can use 2 line code for fix this problem

  1. You should write Top of the page

ob_start()

  1. Before your PDF Output Line $pdf->Output(); to add new line

ob_end_flush();

$pdf->Output();

I think you may solve this problem & enjoy more!

Thanks

Md Salahuddin Khan

MegamindIT

于 2016-03-03T05:26:02.807 回答