开发者

Cakephp TCPDF error: TCPDF ERROR: Some data has already been output, can't send PDF file

开发者 https://www.devze.com 2023-03-27 19:06 出处:网络
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

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 throu开发者_StackOverflow中文版gh 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');
                }


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


Try to clean output buffer by using ob_clean()

or

Avoid printing spaces or any variable before outputting PDF content


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 '';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号