簡體   English   中英

Codeigniter-mPDF導出空白頁

[英]Codeigniter - mPDF exports Blank Page

我使用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);

視圖僅接受3個參數:第一視圖頁面,第二數據數組,第三布爾返回視圖。 $data應該被刪除。

$html = $this->load->view('reportProperties', $viewData, true) ;

加載視圖時發生錯誤。 它應該是三個參數,但提供了四個。

我發現如果發生錯誤,Mpdf僅顯示空白頁。

為了獲取視圖內容,您需要傳遞第三個可選參數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);

另外,請添加reportProperties視圖文件的內容。

編輯1-repostProperties上傳后

您的視圖不適用於mpdf。 首先,圖片網址必須是絕對的,而不是相對的。 另外,對於for循環,我認為這是一個問題,因為您獲得許多頁面。

首先從簡單的視圖文件開始,然后逐步添加其他數據。

請查看mPDF文檔,以了解受支持的內容以及如何分頁內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM