I am trying to export and download the html view incidentView.php to pdf by pressing print button in incidentView.php, using mPDF.I am able to convert to pdf now even though the loading is very slow,but now I am getting error regarding the data that I am trying to get on pdf.Basically I can not convert the Dynamic data can you please help me how I should get them?
I have download mPDF by using:
composer require mpdf/mpdf
config.php
$config['composer_autoload'] = TRUE;
Incident.php Controller
function get_pdf_test($id)
{
$data['incidents'] = $this->incidents_model->getByIdPdf($id);
$data['incidents_history'] = $this->incidents_model->getById_historyPdf($id);
$data['company_name'] = $this->incidents_model->getAllCompanyNamePdf();
require_once (APPPATH. 'vendor/autoload.php');
$path = '/tmp/mpdf';
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
$mpdf = new \Mpdf\Mpdf(['tempDir' => $path]);
$html = $this->load->view('admin/incidents/incidentsPdf',[],true);
$mpdf->WriteHTML($html);
$mpdf->Output();
$mpdf->Output('incidentsPdf.pdf','D');
}
incidentPdf.php view
<div class="TaskView" >
<h2 class="heading" ><?php echo "ASGB_IN".str_pad($incidents->incidents_id, '4', '0', STR_PAD_LEFT);?></h2>
<!-- <form action="<?php echo base_url('get_pdf_test/'.$incidents->id);?>" method="post" > -->
<div class="row">
<div class="form-group col-md-4">
<label for="email">Incidents ID</label>
<input type="text" class="form-control" id="T_id" placeholder="Name" name="T_id" value="<?php echo "ASGB_IN".str_pad($incidents->incidents_id, '4', '0', STR_PAD_LEFT);?>" readonly>
</div>
<div class="form-group col-md-4">
<label for="email">Incidents Name</label>
<input type="text" class="form-control" id="Tname" placeholder="Name" name="Tname" value="<?php echo $incidents->incident_name;?>" readonly>
</div>
<div class="form-group col-md-4">
<label for="pwd">Company Name</label>
<input type="text"class="form-control" id="Cname" name="Cname" value="<?php echo $incidents->company_name;?>"readonly>
</div>
<div class="form-group col-md-4">
<label for="pwd">Project Name</label>
<input type="text" class="form-control" id="Pname" name="Pname" value="<?php echo $incidents->project_name;?>" readonly>
</div>
incident_model.php
function getById_history_pdf($id)
{
$query=$this->db->query("SELECT incidents_id FROM incidents WHERE id = $id");
$get_row = $query->row();
$incident_id = $get_row->incidents_id;
$this->db->select('*');
$this->db->where(array('incidents.incidents_id'=>$incident_id));
$this->db->join('incident_status', 'incidents.id = incident_status.incident_id');
return $this->db->get('incidents')->result_array();
}
function getAllCompanyNamePdf()
{
$query = $this->db->get('company_details');
$query = $this->db->query('SELECT company_name FROM company_details where delete_flag =0');
return $query->result_array();
}
function getByIdPdf($id)
{
return $this->db->get_where('incidents',array('id'=>$id))->row_array();
}
vendor location