我使用mPDF导出 PDF 文档。但是当我使用mPDF导出为PDF时,我得到空白页。我想根据属性Id
显示一些属性信息,但它创建了空白页。mPDF适用于welcome_message.php
但我无法用我的页面制作 PDF。我哪里做错了?
控制器:
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");
}
视图:
<?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>
我对mpdf
不是很熟悉,但我确实看到了一个错误:
$html = $this->load->view('reportProperties', $viewData, $data, true);
View 仅接受 3 个参数:第一个视图页面、第二个数据数组、第三个布尔值以返回视图。 应删除$data
。
$html = $this->load->view('reportProperties', $viewData, true)
;
为了获取视图内容,您需要传递第三个可选参数 TRUE(布尔值( - 请参阅: 将视图作为数据返回
而不是
//load the view and saved it into $html variable
$html = $this->load->view('reportProperties', $viewData, $data, true);
您需要使用:
//load the view and saved it into $html variable
$html = $this->load->view('reportProperties', $viewData, true);
另外,请添加报告属性视图文件的内容。
编辑 1 - 重新发布属性上传后
您的视图不适用于使用 mpdf。 首先,图像网址必须是绝对的,而不是相对的。 另外,对于循环,我认为这是一个问题,因为您可以获得许多页面。
首先从简单的视图文件开始,然后逐步添加另一个数据。
请查看 mPDF 文档以了解支持的内容以及如何对内容进行分页。
加载视图时出错。它应该是三个参数,但提供了四个参数。
我发现 Mpdf 仅在发生错误时才显示空白页。