Codeigniter PDF不起作用

时间:2013-11-13 06:24:07

标签: php codeigniter pdf mpdf

在下面的codeigniter代码中,我想创建一个pdf文件,但它显示网页。我下载教程从这个网站http://blog.luutaa.com/php/generating-a-pdf-using-codeigniter/我创建帮助器,我创建mpdf文件夹并放入所有提取的文件在它中并放置pdf的控制器代码。但问题没有解决。

控制器:

<?php

class Help extends ci_controller
{
    function index()
    {   

        $this->load->view('help_view');
    }   
    //to create the data and insetin to the coursesubject table

    public function pdf_report(){
 $this->load->helper(array('My_Pdf'));   //  Load helper
 $data = file_get_contents(site_url('http://localhost/seatingreport4/index.php/help')); // Pass the url of html report
 create_pdf($data); //Create pdf
 }
}
?>

查看:

<!DOCTYPE html>
<html>
<head>
<?php include_once('header2.php'); ?>
<div id="showhide">
<?php include_once('menu.php'); ?>
</div>
<a id="toggle" onClick="showorhide('showhide')"><img src="<?php echo base_url('img/m.jpg');  ?>" HEIGHT="40" WIDTH="40" BORDER="0"   alt="logo"style="margin-bottom:7px; margin-top:7px;" /></a></a>

<br>
<div class="gray_bg">
        <div class="container">
            <div class="row welcome_inner">
                <div class="span13">
                    <h1 class="p"><span class="k">///</span> Help</h1>
                </div>
            </div>
        </div>
    </div>
<style>
.k{
color:#339900;
 font-size: xx-large;  
}
.p{

 font-size: xx-large; 
 font-weight:900; 
}
</style>
    <script src="//cdn2.editmysite.com/js/vendor/modernizr.js"></script>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,300,400,700" />



        <link rel="stylesheet" type="text/css" href="http://cdn2.editmysite.com/css/public.css?buildTime=1383786711" />

        <!--[if IE 8]><link rel="stylesheet" type="text/css" href="http://cdn2.editmysite.com/css/public-ie8.css?buildTime=1383786711" /><![endif]-->
        <!--[if IE 7]><link rel="stylesheet" type="text/css" href="http://cdn2.editmysite.com/css/public-ie7.css?buildTime=1383786711" /><![endif]-->


    <script> var loginData = {"use_ssl":true,"redirect":false}; var errorMsgs = {"wrongUserPass":"Wrong username or password","loginToAccess":"Please log-in to access that page","loginAgain":"Please log-in again to continue.","accountDeleted":"Your account was previously deleted","accountExists":"You already have an account. Please log-in.","loginInstead":"You already have an account. Please log-in."}; var DISABLE_SIGNUP_CAPTCHA = true; var facebook = {"app_id":"190291501407","domain":"www.weebly.com","user":false}; </script>


        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

        <script type="text/javascript" src="//cdn1.editmysite.com/libraries/prototype/1.7-custom/prototype.min.js?2"></script>

        <script type="text/javascript" src="http://cdn2.editmysite.com/js/public/main.js?buildTime=1383786711"></script>

</head>


<body class="w-ui homepage">


<form id="weebly-signup">
    <div class="caret"></div>

    <div id="signup-inputs">





        <div

            id="weebly-email"
            class="large block"

            placeholder="Email"
        />

        <div

            id="weebly-new-password"
            class="large block"

            placeholder="Password"
        />
    </div>


    <div class="submit-btns">


    </div>

    <input type="hidden" name="response" id="weebly-login-signup-response" />
    <input type="hidden" name="weebly-campaign" id="weebly-campaign" value="" />

</form>


    </div> <!-- #sidebar-inner -->
</div> <!-- #sidebar -->


<div id="login-box" class="form-popover-box titled-box">
    <form id="weebly-login" method="post" action="https://www.weebly.com/weebly/login.php">
        <div class="caret"></div>





        <input
            type="text"
            id="weebly-username"
            class="large block"
            name="user"
            placeholder="Email or Username"
            value=""
        /><br>

        <input
            type="password"
            id="weebly-password"
            class="large block"
            name="pass"
            placeholder="Password"
        /><br>

        <p class="remember-me">
            <label>
                <input
                    type="checkbox"
                    id="weebly-remember"
                    name="rememberme"
                    checked
                />

            </label>
        </p>





    </form>
</div>      






    <div id="how-it-works" class="section">
        <div class="hgroup">
            <h2>        Tips to work on Seating Application</h2>

        </div>



        <div class="article">
            <ol id="how-it-works-list">
                <li class="tips top">
                    <div class="content"><span class="icon"></span></div>
                </li>
                <li>
                    <h4>        Master</h4>
                    <div class="content">
                        <span class="talkbubble"><span class="icon grow"></span></span>
                        <span class="circle mask"><span class="icon grow" ></span></span>
                        <ul class="bubble">
                            <li>    Exam name,month and year is created in exam master  </li>
                            <li>        Course code and name is created in course master</li>
                            <li>        Subject code and name is created in subject master</li>
                            <li>        Room details  such room name,no of benches,maximum bench capacity,available status and invigilator is created in room master</li>
                        </ul>

                    </div>

                    <br><br><br><br> <br><br><br><br><br><br><br>
                </li>

                <li>
                    <h4>        Details</h4>
                    <div class="content">
                        <span class="talkbubble"><span class="icon create"></span></span>
                        <span class="circle mask"><span class="icon create"></span></span>

                        <ul class="bubble">
                            <li>        Course code and Subject code is created in course subject</li>
                            <li>        Exam name and course code is created in exam course</li>
                            <li>        Register no,name, course code and Subject code for a particular exam is created </li>
                            <li>         Update the course code ,subject code,date and session for particular exam </li>
                        </ul>
                    </div>
                    <br><br><br><br> <br><br><br><br><br>
                </li>
                <li>
                    <h4>        Seating Plan    </h4>
                    <div class="content">
                        <span class="talkbubble"><span class="icon publish"></span></span>
                        <span class="circle mask"><span class="icon publish"></span></span>
                        <ul class="bubble">
                            <li>        Exam name is selected </li>
                            <li>        Date and session is selected </li>
                            <li>        Course code,Subject code and number of student id displayed </li>
                            <li>        Clicking on System generated it displays seat no ,register no and subject code</li> 
                        </ul>
                    </div>
                    <br><br><br><br> <br><br><br>
                </li>
                <li>
                    <h4>        Seating Report </h4>
                    <div class="content">
                        <span class="talkbubble"><span class="icon grow"></span></span>
                        <span class="circle mask"><span class="icon grow"></span></span>
                        <ul class="bubble">
                            <li>        Exam name is selected </li>
                            <li>        Date and session is selected </li>
                            <li>        Course code,Subject code and number of student id displayed </li>
                            <li>        Selecting on the Subject code it display Room no,seat no,register no and invigilator as report  </li>
                            <li>        Clicking on seating summary it displays exam name ,date,session,room no,subject code,register no ,no of students and invigilator</li>      
                        </ul>
                    </div>
                    <br><br><br><br> <br><br><br><br><br>
                </li>
                <li>
                    <h4>        Upload</h4>
                    <div class="content">
                        <span class="talkbubble"><span class="icon grow"></span></span>
                        <span class="circle mask"><span class="icon grow"></span></span>
                        <ul class="bubble">
                            <li>        Exam name is selected </li>
                            <li>        Course code for relevant exam is selected </li>
                            <li>        Subject code for corresponding course code is selected </li>
                            <li>        Choose the csv file which has register no and students name and upload it </li>     
                        </ul>
                    </div>
                    <br><br><br><br> <br><br><br><br><br>
                </li>
                <li class="tips bottom">
                    <div class="content"><span class="icon"></span></div>
                </li>
            </ol>
        </div>
    </div>
    <script>
function showorhide(id){
   if(document.getElementById(id)){    //check the element exists and can be accessed
       var ele = document.getElementById(id);    //get hold of the element
       if(ele.style.display=="none"){   //see if display property is set to none
           ele.style.display="block";       
       }else{
           ele.style.display="none";     
       }
   }
} 
</script>

<script>
$('#showhide').hide();
</script>
<style>
.talkbubble {
   width: 120px;
   height: 80px;
   background:#339900;
   position: relative;
   -moz-border-radius:    10px;
   -webkit-border-radius: 10px;
   border-radius:         10px;
}
.talkbubble:before {


   position: absolute;
   right: 100%;
   top: 26px;
   width: 0;

   height: 0;
   border-top: 13px solid transparent;
   border-right: 26px solid red;
   border-bottom: 13px solid transparent;
}
span.picture1 {
   width:100px; /*width of your image*/
   height:100px; /*height of your image*/
   background-image:url('C:\wamp\www\seatingreport1\img\refresh.jpg');
   margin:0; /* If you want no margin */
   padding:0; /*if your want to padding */
}
</style>

2 个答案:

答案 0 :(得分:0)

我相信site_url不会以这种方式工作。该函数将猜测您的域并将其添加到您给出的参数之前。你应该试试:

site_url("seatingreport4/index.php/help");

它将生成以下

http://localhost/seatingreport4/index.php/help

或者只是在没有site_url函数的情况下编写

file_get_contents("http://localhost/seatingreport4/index.php/help");

答案 1 :(得分:-2)

您可以使用mPDF在Codeigniter中生成PDF。

您可以创建一个控制器类,然后在其中创建函数。然后做一些下面的代码 -

public function mypdf() { 
    $this->load->library('pdf'); 
    $pdf = $this->pdf->load(); 
    $html=$this->load->view('welcome_message',null,true); 
    $pdf->WriteHTML($html); 
    // write the HTML into the PDF 
    $output = 'itemreport' . date('Y_m_d_H_i_s') . '_.pdf'; 
    $pdf->Output("$output", 'I'); 
}

有关详细信息,请参阅有关mPDF codeigniter here的教程。