Reputation: 11
I use mPDF for export PDF Documentation. But I get blank page when I export to PDF using mPDF. I want to show some Property Information according to Property Id
but it creates blank page. mPDF works with welcome_message.php
but I can't make PDF with my page. Where I do mistake?
Controller:
public function getReportProperties($cusId)
{
$this->lang->load('content', $this->session->userdata('people_lang'));
$viewData['customers'] = $this->report_model->get_customers();
$viewData['estateList'] = $this->report_model->getEstatesByCustomer($cusId);
$viewData['byCustomer'] = $this->db->where("cusId", $cusId)->get("customer")->row();
$data = [];
//load the view and saved it into $html variable
$html = $this->load->view('reportProperties', $viewData, $data, true);
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
//this the the PDF filename that user will get to download
$pdfFilePath = "properties.pdf";
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");
}
View:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html <?php if($this->session->userdata('people_lang') == "ar") { echo "dir='rtl'"; } else { echo ""; } ?>">
<head>
<?php $this->load->view("common/head"); ?>
<!-- Includes -->
<?php $this->load->view("reports/includes"); ?>
</head>
<body>
<!-- Page content -->
<div class="page-content">
<!-- Main content -->
<div class="content-wrapper">
<!-- Content area -->
<div class="content">
<!-- Inner container -->
<div class="d-flex align-items-start flex-column flex-md-row">
<!-- Left content -->
<div class="w-100 overflow-auto order-2 order-md-1">
<!-- Task overview -->
<div class="card">
<div class="card-header header-elements-md-inline">
<h5 class="card-title"><?php echo $byCustomer->cosName. ' ' .$byCustomer->cosSurname; ?> | All Property List</h5>
<div class="header-elements">
<a href="#" class="btn bg-teal-400 btn-sm btn-labeled btn-labeled-right"><?php echo date("d.m.Y"); ?> <b><i class="icon-alarm-check"></i></b></a>
</div>
</div>
<div class="col-sm-6 col-xl-12">
<!-- Bar chart in colored card -->
<div class="card bg-grey-200 has-bg-image text-center">
<div class="card-body">
<img src="<?php echo base_url().'upload/report/logo.png' ?>" width="180" alt="">
</div>
<div class="container-fluid">
<div id="chart_bar_color"></div>
</div>
</div>
<!-- /bar chart in colored card -->
</div>
<?php $i = 1; foreach($estateList as $estate) { ?>
<div class="card-body">
<h6 class="font-weight-semibold"><span class="btn rounded-circle bg-grey"><?php echo $i++ ?></span> Property Type: <?php echo $estate->estateTypeEng; ?></h6>
<hr>
<div class="row container-fluid">
<div class="col-md-6">
<div class="mb-4">
<dl>
<dt class="font-size-sm text-primary text-uppercase">City</dt>
<dd><?php if($estate->cityName == '') { echo '-'; } else { echo $estate->cityName; } ?></dd>
<dt class="font-size-sm text-primary text-uppercase">Property Address: </dt>
<dd><?php if($estate->estateAddress == '') { echo '-'; } else { echo $estate->estateAddress; } ?></dd>
<dt class="font-size-sm text-primary text-uppercase">Property Acreage m²: </dt>
<dd><?php if($estate->estateCentare == '') { echo '-'; } else { echo $estate->estateCentare; } ?></dd>
<dt class="font-size-sm text-primary text-uppercase">Heating Type: </dt>
<dd><?php if($estate->heatingNameEn == '') { echo '-'; } else { echo $estate->heatingNameEn; } ?></dd>
<dt class="font-size-sm text-primary text-uppercase">Garden Acreage m²: : </dt>
<dd><?php if($estate->estateGardenArea == '') { echo '-'; } else { echo $estate->estateGardenArea; } ?></dd>
</dl>
</div>
</div>
<div class="col-md-6">
<div class="mb-4">
<dl>
<dt class="font-size-sm text-primary text-uppercase">Number of Room: </dt>
<dd><?php if($estate->estateRoom == '') { echo '-'; } else { echo $estate->estateRoom; } ?></dd>
<dt class="font-size-sm text-primary text-uppercase">Number of Bathroom: </dt>
<dd><?php if($estate->estateBathroom == '') { echo '-'; } else { echo $estate->estateBathroom; } ?></dd>
<dt class="font-size-sm text-primary text-uppercase">Number of Livining Room: </dt>
<dd><?php if($estate->estateSalon == '') { echo '-'; } else { echo $estate->estateSalon; } ?></dd>
<dt class="font-size-sm text-primary text-uppercase">Number of Balcony: </dt>
<dd><?php if($estate->estateBalcony == '') { echo '-'; } else { echo $estate->estateBalcony; } ?></dd>
</dl>
</div>
</div>
</div>
<h6 class="font-weight-semibold" hidden>Requirements</h6>
<p class="mb-3" hidden>So slit more darn hey well wore submissive savage this shark aardvark fumed thoughtfully much drank when angelfish so outgrew some alas vigorously therefore warthog superb less oh groundhog less alas gibbered barked some hey despicably with aesthetic hamster jay by luckily.</p>
<div class="card card-table table-responsive shadow-0" hidden>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Task</th>
<th>Due date</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><span class="font-weight-semibold">Design mockup</span></td>
<td>
<div class="d-inline-flex align-items-center">
<i class="icon-calendar2 mr-2"></i>
<input type="text" class="form-control datepicker p-0 border-0 bg-transparent" value="21 January, 15">
</div>
</td>
<td>Create design mockups for a new app, must be delivered before 1st of March</td>
</tr>
<tr>
<td>2</td>
<td><span class="font-weight-semibold">User interface research</span></td>
<td>
<div class="d-inline-flex align-items-center">
<i class="icon-calendar2 mr-2"></i>
<input type="text" class="form-control datepicker p-0 border-0 bg-transparent" value="24 January, 15">
</div>
</td>
<td>Create a focus group with random people, provide a research statement</td>
</tr>
<tr>
<td>3</td>
<td><span class="font-weight-semibold">New icons set</span></td>
<td>
<div class="d-inline-flex align-items-center">
<i class="icon-calendar2 mr-2"></i>
<input type="text" class="form-control datepicker p-0 border-0 bg-transparent" value="28 January, 15">
</div>
</td>
<td>Create a full set of icons required for the iOS application, send them to team lead for review</td>
</tr>
<tr>
<td>4</td>
<td><span class="font-weight-semibold">Loading optimization</span></td>
<td>
<div class="d-inline-flex align-items-center">
<i class="icon-calendar2 mr-2"></i>
<input type="text" class="form-control datepicker p-0 border-0 bg-transparent" value="1 February, 15">
</div>
</td>
<td>Review image sizes, compress them as much as possible, make sure page loading time is less than 1 second</td>
</tr>
</tbody>
</table>
</div>
<h6 class="font-weight-semibold" hidden>Uploaded files</h6>
<p hidden>A much goodness between destructive that save stupid firefly destructively dog goldfinch continually alas pinched for outside flailed inescapably hey brought rid crud and awakened sobbed extraordinarily wherever deer before tenable yet into dalmatian opposite save close ahead next independent mindful but far.</p>
<div class="row" hidden>
<div class="col-xl-3 col-sm-6">
<div class="card">
<div class="card-img-actions mx-1 mt-1">
<img class="card-img img-fluid" src="../../../../global_assets/images/demo/flat/9.png" alt="">
<div class="card-img-actions-overlay card-img">
<a href="../../../../global_assets/images/demo/flat/9.png" class="btn btn-outline bg-white text-white border-white border-2 btn-icon rounded-round" data-popup="lightbox" rel="group">
<i class="icon-zoomin3"></i>
</a>
<a href="#" class="btn btn-outline bg-white text-white border-white border-2 btn-icon rounded-round ml-2">
<i class="icon-download"></i>
</a>
</div>
</div>
<div class="card-body">
<div class="d-flex align-items-start flex-wrap">
<div class="font-weight-semibold">dashboard_draft.png</div>
<span class="font-size-sm text-muted ml-auto">378Kb</span>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-sm-6">
<div class="card">
<div class="card-img-actions mx-1 mt-1">
<img class="card-img img-fluid" src="../../../../global_assets/images/demo/flat/8.png" alt="">
<div class="card-img-actions-overlay card-img">
<a href="../../../../global_assets/images/demo/flat/9.png" class="btn btn-outline bg-white text-white border-white border-2 btn-icon rounded-round" data-popup="lightbox" rel="group">
<i class="icon-zoomin3"></i>
</a>
<a href="#" class="btn btn-outline bg-white text-white border-white border-2 btn-icon rounded-round ml-2">
<i class="icon-download"></i>
</a>
</div>
</div>
<div class="card-body">
<div class="d-flex align-items-start flex-wrap">
<div class="font-weight-semibold">profile_page.png</div>
<span class="font-size-sm text-muted ml-auto">1.2Mb</span>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-sm-6">
<div class="card">
<div class="card-img-actions mx-1 mt-1">
<img class="card-img img-fluid" src="../../../../global_assets/images/demo/flat/6.png" alt="">
<div class="card-img-actions-overlay card-img">
<a href="../../../../global_assets/images/demo/flat/9.png" class="btn btn-outline bg-white text-white border-white border-2 btn-icon rounded-round" data-popup="lightbox" rel="group">
<i class="icon-zoomin3"></i>
</a>
<a href="#" class="btn btn-outline bg-white text-white border-white border-2 btn-icon rounded-round ml-2">
<i class="icon-download"></i>
</a>
</div>
</div>
<div class="card-body">
<div class="d-flex align-items-start flex-wrap">
<div class="font-weight-semibold">shopping_cart.png</div>
<span class="font-size-sm text-muted ml-auto">1.8Mb</span>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-sm-6">
<div class="card">
<div class="card-img-actions mx-1 mt-1">
<img class="card-img img-fluid" src="../../../../global_assets/images/demo/flat/12.png" alt="">
<div class="card-img-actions-overlay card-img">
<a href="../../../../global_assets/images/demo/flat/9.png" class="btn btn-outline bg-white text-white border-white border-2 btn-icon rounded-round" data-popup="lightbox" rel="group">
<i class="icon-zoomin3"></i>
</a>
<a href="#" class="btn btn-outline bg-white text-white border-white border-2 btn-icon rounded-round ml-2">
<i class="icon-download"></i>
</a>
</div>
</div>
<div class="card-body">
<div class="d-flex align-items-start flex-wrap">
<div class="font-weight-semibold">sales_statistics.png</div>
<span class="font-size-sm text-muted ml-auto">2.0Mb</span>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="card-footer d-sm-flex justify-content-sm-between align-items-sm-center">
<span class="d-flex align-items-center">
<span class="badge badge-mark border-green mr-2"></span>
<?php echo $byCustomer->cosName. ' ' .$byCustomer->cosSurname; ?> has <?php
$cusId = $byCustomer->cusId;
$this->db->select('*');
$this->db->where('cusId', $cusId);
$query = $this->db->get('estate');
$num = $query->num_rows();
echo $num; ?> <?php if($num > 1) { echo 'Properties.'; } elseif($num = 1) { echo 'Property.'; } elseif($num = 0) { echo 'no any Property yet.'; }?>
</span>
<ul class="list-inline list-inline-condensed mb-0 mt-2 mt-sm-0">
<span class="d-flex align-items-right">
<?php echo date('Y'); ?>
</span>
</ul>
</div>
</div>
<!-- /task overview -->
</div>
<!-- /left content -->
</div>
<!-- /inner container -->
</div>
<!-- /content area -->
</div>
<!-- /main content -->
</div>
<!-- /page content -->
</body>
</html>
Upvotes: 0
Views: 1409
Reputation: 2073
In order to get the view content you need to pass a third optional parameter, TRUE (boolean) - please see: Returning views as data
Instead of
//load the view and saved it into $html variable
$html = $this->load->view('reportProperties', $viewData, $data, true);
you need to use:
//load the view and saved it into $html variable
$html = $this->load->view('reportProperties', $viewData, true);
Also, please add the content of the reportProperties view file.
EDIT 1 - after repostProperties uploaded
Your view is not valid for working with mpdf. First, images url's need to be absolut and not relative. Also, the for loop, I think here is a problem as you get many pages.
First start with simple view file and then, step by step add another data.
Please check the mPDF documentation to see what is supported and how you can paginate your content.
Upvotes: 0
Reputation: 67
The error occurred on loading view. It should be three parameters,but four was supplied.
I found that Mpdf just only display blank page if the error have been occurred.
Upvotes: 0
Reputation: 9265
I'm not super familiar with mpdf
but I do see an error:
$html = $this->load->view('reportProperties', $viewData, $data, true);
view only accepts 3 params: 1st view page, 2nd data array, 3rd bool to return view. $data
should be removed.
$html = $this->load->view('reportProperties', $viewData, true)
;
Upvotes: 1