如何将php html页面保存为pdf

如何将php html页面保存为pdf,php,html,pdf,swiftmailer,Php,Html,Pdf,Swiftmailer,我有一个控制器功能来打印过道票 function print_hallticket() { if (!$this->library['authentication']->permission(3)) { $this->redirect('gateway/no-access'); } $this->model('registration'); $data['id']=$th

我有一个控制器功能来打印过道票

  function print_hallticket() {

        if (!$this->library['authentication']->permission(3)) {
            $this->redirect('gateway/no-access');
        } 

         $this->model('registration');
         $data['id']=$this->url_slice(3,'');

         $data['student_details'] = $this->model['registration']->student_details($this->url_slice(3,''));


        $this->view("print/hallticket",$data);
    }
打印页面
hall_ticket.php
如下所示,当单击打印按钮时,它将打印hall_ticket

<html lang="en">
<html>
<head>
<base href="<?php echo $this->get_base_url(); ?>" />
<title>Print</title>
<head>
<meta charset="UTF-8">
<style type="text/css">
/*  tr.ths td{
    border-bottom:1pt solid black; 
    border-top:1pt solid black; 
     border-left:1pt solid black; 
      border-right:1pt solid black; 
}*/
                body{font-family:Arial,sans-serif; margin:0px; padding:0px;  } 
                .page{ width:795px; height: auto;  margin: 0px auto;  font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;}  
                @media print {@page { margin: 30px 45px 0 45px;  visibility: hidden;   } .page-break {page-break-before: always;} }  

            </style>

<body onLoad="javascript:window.print();" >
<div class="page" id="pageid">
    <div style="width:780px;height:auto;margin:auto; background:url() repeat-x top; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; ">

        <div style="width:750px; height:auto; margin:auto; padding:10px 0 0 0;  float:left;  height:65px;">
            <table>
                <tr>   
                    <td width="70%"><div style="width:30%; height:65px;  margin-left: 15px; float:left; font-size:12px;"><img src="assets/images/logo1.png" height="85px"></div></td>
                    <td width="70%"><div style="width:600px; margin-left: 50px; color:#0000; float:left; font-size:20px;  font-weight: bold;"><span style="margin-left: 30px;"><?php  foreach($student_details as $rows){ echo $rows->exam_name; } ?></span><br/><span style="font-size:12px;margin-left: 150px; ">ELIGIBILITY TEST</span> 

                </tr>

            </table>

        </div>


        <div style="width:750px; float:left; height:25px;  background:#ffff; -webkit-border-radius: 3px;    -moz-border-radius: 3px;border-radius: 3px; margin:20px auto 0 15px; padding:5px 0 0 7px;">
            <table  style="text-align:  center;"  >
                <tr>
                    <td colspan="2"><div style="width:175px; margin-left: 210px; color:#0000; float:left; font-size:14px; padding:0 0 0 55px; font-weight: bold;"><u>ADMIT CARD </u></div>  </td>


                </tr>

            </table>


        </div>
                        <div>
                        <?php foreach($student_details as $row){  ?>
        <div style="width:75%; float:left; height:35px;  background:#ffff; -webkit-border-radius: 3px;  -moz-border-radius: 3px;border-radius: 3px; margin:10px auto 20px 15px; padding:5px 0 0 7px; ">
            <table>
                <tr></tr>
                <!--<tr  style="width:100% ;font-size:16px;font-weight: bold;" class="ths">  <td >Roll No</td ><td >:</td ><td ><?php // echo EXAMCODE.$row->student_rollno; ?>  </td></tr>-->
                 <tr>

                 </tr>
            </table>

            <table  style="text-align:  left;font-size: 18px;width:600;"  >
                <tr></tr>

                 <tr>

                 </tr><tr  style=" font-size:17px;font-weight: bold;" class="ths">  <td >Roll No</td ><td >:</td ><td ><?php echo $row->exam_code.$row->student_rollno; ?>  </td></tr>

                <tr>

                    <td style="width:30%">Venue Of Test</td>
                    <td>:</td><td  ><?php echo $row->exam_center_name; ?> </td>

                </tr>
                  <tr>

                    <td >Name </td>
                       <td>:</td><td><?php echo  $row->student_name; ?>  </td>

                    <td ></td>


                </tr>
                 <tr>
                      <td >Father's Name</td>
                       <td>:</td><td><?php echo $row->student_parent; ?> </td>
                 </tr>
                  <tr>
                      <td valign="top">Address</td>
                       <td valign="top">:</td><td><?php echo $row->student_address; ?><br /><?php echo $row->student_district; ?><br /><?php echo $row->student_pin; ?> </td>
                 </tr>
                  <tr>
                      <td >Email ID</td>
                       <td>:</td><td><?php echo $row->student_email; ?>  </td>
                 </tr>
                  <tr>
                      <td >Date Of Test</td>
                       <td>:</td><td><?php echo $row->exam_date; ?>    </td>
                 </tr>
                  <tr>
                      <td >Time</td>
                       <td>:</td><td><?php echo date('h:i:s a ', strtotime($row->exam_starttime)); ?>  To <?php echo  date('h:i:s a ', strtotime($row->exam_endtime)) ; ?>    </td>
                 </tr>

            </table>


        </div>
                        <div style="width:25%; float:right;   ">

                            <table style="border: 2 ;text-align:  left;font-size: 20px;width:200;" >

                                 <tr>  <td>   </td></tr>
                            <tr>  <td>  <?php if ($row->student_image != "") { ?>
                        <img src="<?php echo $this->get_base_url(); ?>public/uploads/students/<?php echo $row->student_image ?>" height="150px"/>
                        <?php } else { ?>
                        <img src="assets/images/imagesper.png" />
                            <?php } ?> 
                        </div>
                         <?php } ?>
  </td></tr>
</table>  </div></div>

        <div style="clear:both;"></div>






</div>
<div style="width:750px; text-align: center;  height:auto; margin:auto; padding:20px 0 0 0; color:#202020; font-weight: bold; font-size:11px;">

</div>

<div style="width:550px; height:33px; margin:auto; padding:20px 0 0 0; color:#202020; font-size:12px; text-align:right;">

</div>

</div> 
    <div style="width:780px;height:auto;margin:auto; background:url() repeat-x top; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; ">
         <table style="border: 2 ;text-align:  left;font-size: 20px;width:200;" >

                               <tr>  </tr>   <tr>  </tr>   <tr>  </tr>   <tr>  <td>  

                                     </td></tr>


</table>  

    </div>
<div class="page-break"></div>


        </body>
</html>

From of view是从HTMl创建PDF的最佳开源软件,它支持阿拉伯语和RTL语言,您可以添加所需的字体,您可以制作页眉和页脚,然后重复每页,可以将HTMl字符串传递给writeHTML函数以输出PDF,您还可以在下载的完整源代码中找到简单的示例,帮助您完成任务。

试试看

wkhtmltopdf和wkhtmltoimage是开源(LGPLv3)命令行 使用Qt将HTML呈现为PDF和各种图像格式的工具 WebKit渲染引擎。这些都是完全“无头”的,不需要 需要显示或显示服务


wkhtmltopdf google.pdf

CTRL+p并另存为pdf。否则,您需要使用fpdf创建pdf。@Sougata:如何在$client->convertURI中指定控制器路径