Cakephp TCPDF 错误:TCPDF 错误:某些数据已输出,无法发送 PDF 文件
我已按照以下链接中的说明安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你只需在 switch 语句上方添加 ob_end_clean() 即可。它会清除标头
you just add ob_end_clean() above the switch statement.thats it..it will clear the header
尝试使用
ob_clean()
清理输出缓冲区或
在输出 PDF 内容之前避免打印空格或任何变量
Try to clean output buffer by using
ob_clean()
or
Avoid printing spaces or any variable before outputting PDF content
删除该行
如果您添加了该行,也请从代码中
。 PS 如果我将 ob_clean() 放在 Output 公共函数的最后 2 行中,如 rajapandian 和 Kamil Ilyas 所提到的,它对我来说效果很好:
Also remove the line
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: