FPDF error: Some data has already been output, can#39;t send PDF(FPDF错误:部分数据已经输出,无法发送PDF)
问题描述
我正在为我的项目使用 fpdf 库,并且我正在使用它来扩展其中一个Drupal 模块.这些行
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:FPDF错误:部分数据已经输出,无法发送PDF
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
