FPDF错误:已经输出了一些数据,无法发送PDF

我正在为我的项目使用fpdf库,并且正在使用它来扩展drupal模块之一。这些线


$pdf = new FPDF();

$pdf->AddPage();

$pdf->SetFont('Arial','B',16);

$pdf->Cell(40,10,'Hello World!');

$pdf->Output();

给我一个错误:FPDF错误:已经输出了一些数据,无法发送PDF


我尝试在drupal区域名称test.php之外的单独文件中创建此文件,并在查看时起作用。这里有人知道为什么这行不通吗?或者这里的任何人都可以为我指出一个正确的pdf库,我可以在drupal中使用它来查看HTML到PDF格式。


侃侃无极
浏览 422回答 3
3回答

繁星淼淼

为了使fpdf正常工作,在fpdf生成的内容之外根本没有任何输出。例如,这将起作用:<?php$pdf = new FPDF();$pdf->AddPage();$pdf->SetFont('Arial','B',16);$pdf->Cell(40,10,'Hello World!');$pdf->Output();?>虽然这不会(请注意开始<?标记前的前导空格)&nbsp;<?php$pdf = new FPDF();$pdf->AddPage();$pdf->SetFont('Arial','B',16);$pdf->Cell(40,10,'Hello World!');$pdf->Output();?>另外,这也不起作用(echo会破坏它):<?phpecho "About to create pdf";$pdf = new FPDF();$pdf->AddPage();$pdf->SetFont('Arial','B',16);$pdf->Cell(40,10,'Hello World!');$pdf->Output();?>我不确定事物的drupal方面,但是我知道非fpdf输出绝对为零是fpdf工作的要求。

慕尼黑8549860

ob_start ();在顶部添加,最后添加ob_end_flush();<?php&nbsp; &nbsp; ob_start();&nbsp; &nbsp; require('fpdf.php');&nbsp; &nbsp; $pdf = new FPDF();&nbsp; &nbsp; $pdf->AddPage();&nbsp; &nbsp; $pdf->SetFont('Arial','B',16);&nbsp; &nbsp; $pdf->Cell(40,10,'Hello World!');&nbsp; &nbsp; $pdf->Output();&nbsp; &nbsp; ob_end_flush();&nbsp;?>

莫回无

给我一个错误,如下所示:FPDF error: Some data has already been output, can't send PDF克服此错误:转到fpdf.php该行,转到行号996function Output($name='', $dest='')之后,进行如下更改:function Output($name='', $dest='') {&nbsp; &nbsp;&nbsp; &nbsp; ob_clean();&nbsp; &nbsp; &nbsp;//Output PDF to so
打开App,查看更多内容
随时随地看视频慕课网APP