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