FPDF错误:有些数据已经输出,无法发送PDF [英] FPDF error: Some data has already been output, can't send PDF

查看:283
本文介绍了FPDF错误:有些数据已经输出,无法发送PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的项目使用 fpdf 库,我使用它来扩展其中一个硬盘模块这些行

I am using the fpdf library for my project, and I'm using this to extend one of the drupal module. These lines

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

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

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

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

I tried creating this in a separate file outside the drupal area name test.php and when viewed it worked. Anyone here know why this don't work? Or anyone here can point me a right pdf library which I can use in drupal to view HTML to PDF format.

推荐答案

对于fpdf要正常工作,除了fpdf生成之外,根本就不能输出任何输出。例如,这将工作:

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();
?>

此外,这也不会奏效( echo 将会破坏它):

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();
?>

我不知道drupal方面的事情,但我知道绝对零非fpdf输出是fpdf工作的一个要求。

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错误:有些数据已经输出,无法发送PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆