0

I have been flowing this post to generate a pdf but the output is blank and there is no error displayed , i have put :

public function generate_pdf()
{
    $this->load->library('mpdf');
    $mpdf=new mPDF('utf-8','A4');
    $mpdf->WriteHTML('<p>HTML content goes here...</p>');
    $mpdf->Output();
}

When i put :

public function generate_pdf()
{
    $this->load->library('mpdf');
    $mpdf=new mPDF('utf-8','A4');
    $mpdf->debug = true;
    $mpdf->WriteHTML('<p>HTML content goes here...</p>');
    $mpdf->Output();
}

referred to this answer , i get this error :

Output has already been sent from the script - PDF file generation aborted.
Community
  • 1
  • 1
Wassim Sboui
  • 1,692
  • 7
  • 30
  • 48
  • Check your error logs - it could be that a PHP warning or error could be adding output before you get a chance to. – Darrrrrren Nov 08 '12 at 14:29

2 Answers2

5

it is working using ob_end_clean() that erase the output buffer and turn off output buffering

public function generate_pdf()
{
   ob_end_clean();
   $this->load->library('mpdf');
   $mpdf=new mPDF('utf-8','A4');
   $mpdf->debug = true;
   $mpdf->WriteHTML('<p>HTML content goes here...</p>');
   $mpdf->Output();
}
Wassim Sboui
  • 1,692
  • 7
  • 30
  • 48
1

Some output is already sent to the browser from your script. Please check your source code. You may want to use output buffering as well.

Ene
  • 464
  • 2
  • 7
  • i have wrap my code with ob_start(); annd ob_end_clean(); but it still not working – Wassim Sboui Nov 08 '12 at 14:49
  • Output buffering won't help if your code is generating errors as you'll be buffering the errors into your output as well. Given you're setting debugging on, it's obviously going to be generating log messages. – Darrrrrren Nov 08 '12 at 14:50