Cakephp TCPDF 错误:TCPDF 错误:某些数据已输出,无法发送 PDF 文件

发布于 2024-11-29 05:49:27 字数 663 浏览 2 评论 0原文

我已按照以下链接中的说明安装了 TCPDF: http://bakery .cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

但是当我把这个通过控制器,我收到以下错误: TCPDF 错误:某些数据已输出,无法发送 PDF 文件

我似乎无法弄清楚原因。我尝试搜索视图文件以确保任何 PHP 标签之前没有空格。我别无选择...

有什么我可以检查的吗?

我想我知道错误来自哪里。以下是 tcpdf.php 中输出错误的代码:

case 'D': {
                // download PDF as file
                if (ob_get_contents()) {
                    $this->Error('Some data has already been output, can\'t send PDF file');
                }

I have installed TCPDF following instructions on below link:
http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

However when I put this through controller, I am getting below error:
TCPDF ERROR: Some data has already been output, can't send PDF file

I cannot seem to figure out why. I've tried search through view files to ensure there are no spaces before any PHP tags. I'm out of choices...

Is there anything that I could check?

I think I know where the error is coming from. Below is the code for where the error is getting outputted in tcpdf.php:

case 'D': {
                // download PDF as file
                if (ob_get_contents()) {
                    $this->Error('Some data has already been output, can\'t send PDF file');
                }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缱倦旧时光 2024-12-06 05:49:27

你只需在 switch 语句上方添加 ob_end_clean() 即可。它会清除标头

you just add ob_end_clean() above the switch statement.thats it..it will clear the header

枉心 2024-12-06 05:49:27

尝试使用 ob_clean() 清理输出缓冲区

在输出 PDF 内容之前避免打印空格或任何变量

Try to clean output buffer by using ob_clean()

or

Avoid printing spaces or any variable before outputting PDF content

GRAY°灰色天空 2024-12-06 05:49:27

删除该行

require_once('tcpdf/config/lang/eng.php');

如果您添加了该行,也请从代码中

。 PS 如果我将 ob_clean() 放在 Output 公共函数的最后 2 行中,如 rajapandian 和 Kamil Ilyas 所提到的,它对我来说效果很好:

public function Output($name='doc.pdf', $dest='I') {
    //LOTS OF CODE HERE....}
    }
           ob_end_clean(); //add this line here 
    return '';
}

Also remove the line

require_once('tcpdf/config/lang/eng.php');

from your code if you added it in.

P.S. The ob_clean() works well for me if I put it in the 2nd last line of the Output public function as mentioned by rajapandian and Kamil Ilyas:

public function Output($name='doc.pdf', $dest='I') {
    //LOTS OF CODE HERE....}
    }
           ob_end_clean(); //add this line here 
    return '';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文