简体   繁体   English

部分数据已经输出,无法发送PDF文件

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

I'm using fpdf in creating pdf in php and I'm getting this error when running:我在 php 中创建 pdf 时使用 fpdf,运行时出现此错误:

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):这是我的 php 代码(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):另一个(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.输出应该是打印在pdf表单中的文本字段中输入的ID号的所有信息。

put if isset on your code.把 ifisset 放在你的代码上。 ie 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);

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.这意味着在使用 mPDF 创建 pdf 之前,一些数据存储在发送到浏览器的缓冲区中。 Therefore it is unable to create PDF.因此无法创建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.只需这样做.. 在页面的第一行添加以下 php 内置函数,如果您正在为 pdf 准备数据。

op_start();

And add this below php built-in function before mPDF code (before where you are calling mpdf)并在 mPDF 代码之前(在您调用 mpdf 之前)在 php 内置函数下方添加此内容

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.以便在处理 mPDF 之前清除所有缓冲区输出。

You should use before the data you want to output in pdf.您应该在要以 pdf 格式输出的数据之前使用。

ob_start();

Then use ob_end_clean().然后使用 ob_end_clean()。

ob_end_clean();
$pdf->Output(time().'.pdf', 'D')

Error : Some data has already been output, can't send PDF file错误:部分数据已经输出,无法发送PDF文件

You can use 2 line code for fix this problem您可以使用 2 行代码来解决此问题

  1. You should write Top of the page你应该写 Top of the page

ob_start() ob_start()

  1. Before your PDF Output Line $pdf->Output();在您的 PDF 输出行之前$pdf->Output(); to add new line添加新行

ob_end_flush(); ob_end_flush();

$pdf->Output(); $pdf->输出();

I think you may solve this problem & enjoy more!我想你可以解决这个问题并享受更多!

Thanks谢谢

Md Salahuddin Khan萨拉赫丁汗

MegamindIT MegamindIT

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取TCPDF:一些数据已经输出,无法在Laravel 4中发送PDF文件 - Getting TCPDF:Some data has already been output, can't send PDF file in Laravel 4 使用FPDF致命错误:有些数据已经输出,无法发送PDF文件? - Fatal error using FPDF:Some data has already been output, can't send PDF file? FPDF 错误:部分数据已经输出。 无法发送 PDF 文件 - FPDF error: some data has already been output. Can't send PDF file FPDF错误:已经输出了一些数据,无法发送PDF文件 - FPDF error: Some data has already been output, can't send PDF file TCPDF ERROR:部分数据已经输出,无法发送PDF文件 - TCPDF ERROR: Some data has already been output, can't send PDF file TCPDF ERROR: Some data has been output to browser, can't send PDF file - TCPDF ERROR: Some data has already been output to browser, can't send PDF file TCPDF &amp; mPDF 错误:部分数据已经输出到浏览器,无法发送PDF文件 - TCPDF & mPDF error: Some data has already been output to browser, can't send PDF file magento FPDF错误:已经输出了一些数据,无法发送PDF文件 - magento FPDF error: Some data has already been output, can't send PDF file FPDF错误:有些数据已经输出,无法在000webhost上发送PDF文件 - FPDF error: Some data has already been output, can't send PDF file on 000webhost mPDF错误:部分数据已经输出到浏览器,无法发送PDF文件 - mPDF error: Some data has already been output to browser, can't send PDF file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM