Welcome Guest, Not a member yet? Register   Sign In
mpdf with dynamic data
#1

[eluser]soyut[/eluser]
Hi,

I have created a page for reporting. And, it is getting a dynamic data based on whatever queries selected.
Example;
Users can get a report between two different dates based on their 'income/expense' selection and 'type' selections.

After a submit report is created in another page: report_view2.php

at the bottom of report_view2.php i have created a link so that, when they click it they can get it in pdf format.

I am using mpdf library to do that. But somehow it is giving only blank pdf page.

I can create static pdf
Code:
$mpdf->WriteHTML('<p>Hello Tudip Technologies</p>');

but, doing something wrong with this dynamic content.


here is my controller function for the dynamic content.

Code:
public function topdf()
         {
          
           if ($this->input->post('submit'))
          {
            if($this->input->post('date1')){
                if($this->input->post('date2')){
          $data['reports'] = $this->blog_model2->reporting();
          $reports =array();    
    }}}
        $html = $this->load->view('report_view2', $data);
      
        $mpdf=new mPDF();
        
    $mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
    
    $mpdf->WriteHTML($html,2);
    
        $mpdf->Output('mpdf.pdf','I');
        
          }
Can anyone advise me about in this issue.

Thanks.
#2

[eluser]soyut[/eluser]
seems noone using mpdf Sad
#3

[eluser]fatangel26[/eluser]
Try : $html = $this->load->view('report_view2', $data, TRUE);
#4

[eluser]soyut[/eluser]
hi, fatangel, Thanks for the reply.

I have tried this , it is giving me something but not the data from database. Sad
#5

[eluser]fatangel26[/eluser]
- Array $data['reports'] have value ?. Check it. My code for export to pdf:
Code:
public function export2pdf()
        {
   $this->load->library('mpdf');
            $mpdf = new mPDF('utf-8');
  
   $mpdf->mirrorMargins = 1; // Use different Odd/Even headers and footers and mirror margins

   $mpdf->defaultheaderfontsize = 10; /* in pts */
   $mpdf->defaultheaderfontstyle = B; /* blank, B, I, or BI */
   $mpdf->defaultheaderline = 1;  /* 1 to include line below header/above footer */

   $mpdf->defaultfooterfontsize = 12; /* in pts */
   $mpdf->defaultfooterfontstyle = B; /* blank, B, I, or BI */
   $mpdf->defaultfooterline = 1;  /* 1 to include line below header/above footer */


   $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Hoá đơn');
   $mpdf->SetFooter('{PAGENO}/{nb}|Winesey.com.vn'); /* defines footer for Odd and Even Pages - placed at Outer margin */

   $mpdf->SetFooter(array(
    'L' => array(
     'content' => 'Text to go on the left',
     'font-family' => 'sans-serif',
     'font-style' => 'B', /* blank, B, I, or BI */
     'font-size' => '10', /* in pts */
    ),
    'C' => array(
     'content' => '- {PAGENO} -',
     'font-family' => 'serif',
     'font-style' => 'BI',
     'font-size' => '18', /* gives default */
    ),
    'R' => array(
     'content' => 'Printed @ {DATE j-m-Y H:m}',
     'font-family' => 'monospace',
     'font-style' => '',
     'font-size' => '10',
    ),
    'line' => 1,  /* 1 to include line below header/above footer */
   ), 'E' /* defines footer for Even Pages */
   );
  
   $order_id = $this->uri->segment(4);
            
            $data['order'] = $this->MCart->getorder(array('order_id' => $order_id));
            
            $data['order_items'] = $this->MCart->get_order_items($order_id);    
  
   //echo $this->load->view("backend/cart/printorder",$data,TRUE);
  
   $mpdf->WriteHTML($this->load->view("backend/cart/printorder",$data,TRUE));
   $mpdf->Output();
  
        }
#6

[eluser]soyut[/eluser]
I have checked , it seems nothing wrong but still not getting dynamic data printed to pdf.

Here is my model

Code:
function reporting()
    {
    

        $date1 = explode('/',$this->input->post('date1'));
        $new_date1 = $date1[2].'-'.$date1[0].'-'.$date1[1];
        
        $date2 = explode('/',$this->input->post('date2'));
        $new_date2 = $date2[2].'-'.$date2[0].'-'.$date2[1];
        
        $date1 = $new_date1;
        $date2 = $new_date2;
        
        // $this->form_validation->set_rules($date1, 'required');
         // $this->form_validation->set_rules($date2, 'required');
        
        
        $inex = $this->input->post('inex');
        $type = $this->input->post('type');
        $amount = $this->input->post('amount');
        $notes = $this->input->post('notes');
        
        
    
        
  
        
           if($this->input->post('inex')=='Both'){
            
                if($this->input->post('type')=='Both'){
                    
                    $query = $this->db->query("SELECT * FROM my_account WHERE date BETWEEN '$date1' AND '$date2'  ");
        
                    return $query->result();
            
                    }else{
                        
                        $query = $this->db->query("SELECT * FROM my_account WHERE type='$type' AND date BETWEEN '$date1' AND '$date2'  ");
                    
                        return $query->result();
                        
                        }
            
        }  else {    
            
             $query = $this->db->query("SELECT * FROM my_account WHERE inex='$inex' and type='$type' AND date BETWEEN '$date1' AND '$date2'  ");
        
        }
             return $query->result();
        
      
      
    }


Here is my view

Code:
<div id="innerwrapper">
    <div id="content">
    <h3>This is the Report View</h3>
    
    <div id="sum">







<table class="tableizer-table">
<tr class="tableizer-firstrow">
<th>Date</th>
<th>Inex</th>
<th>Type</th>
<th>Amount</th>
<th>Notes</th>

</tr>

&lt;?php if($this->input->post('submit')) {


foreach($reports as $rep){
echo '<tr>';
  
echo "<td>". $rep->date ."</td>";
echo "<td>" . $rep->inex ."</td>";
echo "<td>". $rep->type ."</td>";
echo "<td>". $rep->amount ."</td>";
echo "<td>". $rep->notes ."</td>";

  echo "</tr>";
  }
  }
  else{
    


echo"<tr><td colspan='7' There is nothing to display</td></tr>";
  }
  echo "<tr><td colspan='7'>". anchor('blog2/topdf/','Print it to PDF') ."</td></tr>";
echo "</table>"
  ?&gt;





    
    </div>


#7

[eluser]soyut[/eluser]
anyone ?
#8

[eluser]soyut[/eluser]
This is the my controller now , i cant get dynamic data. can get only static.


Code:
public function topdf()
         {
          
        
          $data['reports'] = $this->blog_model2->reporting();
          $reports =array();    
      
      
          
      
        $html = $this->load->view('report_view2', $data, TRUE);
    
        $mpdf=new mPDF();
            
        $mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
    
    
    
        $mpdf->WriteHTML($html,2);
    
        $mpdf->WriteHTML($this->output->get_output(),2);
        $mpdf->Output('mpdf.pdf','I');
        
          }
#9

[eluser]Brad K Morse[/eluser]
I have done what you're trying to accomplish, but using dompdf.

Before trying dompdf (if that is an option), strip everything in your view, only include one dynamic variable to determine if its a dynamic problem or something else.
#10

[eluser]soyut[/eluser]
Hi, brad. I tried stripping. Didnt work. Now trying dompdf but giving the same. No dynamic data. maybe the problem is about output buffering. If you kindly show your code i can check it. Thats fine if its not possible. Thanks for your interest.




Theme © iAndrew 2016 - Forum software by © MyBB