Wassim Sboui
Wassim Sboui

Reputation: 1820

Using mpdf with codeigniter generate blank output

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.

Upvotes: 0

Views: 7276

Answers (2)

Wassim Sboui
Wassim Sboui

Reputation: 1820

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();
}

Upvotes: 5

Ene
Ene

Reputation: 464

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.

Upvotes: 1

Related Questions