Nisarg Bhavsar
Nisarg Bhavsar

Reputation: 956

PDF is not generated in codeigniter and display blank

I am working in codeigniter.I have downloaded TCPDF for creating pdf. I have followed all step for generating pdf in codeigniter.

My controller is:

function list_branch_report()
{
    if($this->input->post('submit'))
    {
        $this->load->library('Pdf');
        $pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
        $pdf->SetTitle('Pdf Example');
        $pdf->SetHeaderMargin(30);
        $pdf->SetTopMargin(20);
        $pdf->setFooterMargin(20);
        $pdf->SetAutoPageBreak(true);
        $pdf->SetAuthor('Author');
        $pdf->SetDisplayMode('real', 'default');
        $pdf->Write(5, 'CodeIgniter TCPDF Integration');
        $pdf->AddPage();
        $pdf->Output('pdfexample.pdf', 'I');            

        $branch_id = $this->input->post('br_name');
        $branch_code = $this->input->post('branch_code');

        $query1 = $this->db->query("select * from branch_bal where branch_id = '$branch_id'");
        $result1 = $query1->result();           

        $query2 = $this->db->query("select * from cash_depo where bid = '$branch_id'");
        $result2 = $query2->result();




        $this->load->view("admin/list_branch_report",array('br_result'=>$result1,'cash_result'=>$result2,'b_code'=>$branch_code));

    }

And my view page is:

  <div style="float:left;width:100%">
     <center><h1> Branch Report </h1></center>
  </div>

When I try to generate pdf then it will display blank.

Upvotes: 2

Views: 2011

Answers (3)

shankar kumar
shankar kumar

Reputation: 648

use mpdf instead of tpdf and send html that you want to convert in pdf.

Upvotes: 0

Nisarg Bhavsar
Nisarg Bhavsar

Reputation: 956

I have written ob_start(); before the load view page.Then i have written

$html = $this->load->view("admin/list_branch_report",array('br_result'=>$result1,'cash_result'=>$result2,'b_code'=>$branch_code),true);
$pdf->writeHTML($html, true, false, true, false, '');
 ob_clean();
 $pdf->Output();

this code. So it works perfect.

Thanks to all.

Upvotes: 0

mokNathal
mokNathal

Reputation: 553

where are you writing HTML to PDF I haven't work on tcpdf but as my experience with mpdf as far as i know there should a function like

$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);

please refer tcpdf documentation for writeHTML() or writeHTMLCell() functions

http://www.tcpdf.org/doc/code/classTCPDF.html

or refer examples

http://www.tcpdf.org/examples.php

you have to assign codeigniter view to variable for that give last attribute as true

$html= $this->load->view("admin/list_branch_report",array('br_result'=>$result1,'cash_result'=>$result2,'b_code'=>$branch_code),true);

and then assign this to

$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);

Upvotes: 1

Related Questions